c#控制台应用程序中的重载方法错误

时间:2013-02-11 08:57:00

标签: c#

我有一个类创建一个在边框上有不同颜色的Box。我的代码中出现错误,上面写着“方法没有重载'SetCursorPosition'需要3个参数。这是我的代码:

class TitledBox : ColoredBox
{
    private string title;
    private ConsoleColor titleColor;

    public TitledBox(Point p, int width, int height, ConsoleColor backColor, string title, ConsoleColor titleColor)
        : base(p, width, height, backColor)
    {
        if (title.Length > width)
            this.title = title.Substring(0, width);
        else
            this.title = title;

        this.titleColor = titleColor;
    }

    public override void Draw()
    {
        for (int j = 0; j < height; j++)
        {
            Console.SetCursorPosition(p.X, p.Y, + j);
            Console.BackgroundColor = backColor;
            if  ( j == 0)    
            {
                Console.ForegroundColor = titleColor;
                Console.Write(title);
               for (int i = 0; i < width - title.Length; i++)
               {
                   Console.Write(' ');
               }
            }
            else
            {
                for (int i = 0; i < width; i++)
                Console.Write(' ');
            }
        }
    }

}

关于我做错的任何想法?

3 个答案:

答案 0 :(得分:0)

您的Console.SetCursorPosition应如下所示

Console.SetCursorPosition(int Left, int Top);

答案 1 :(得分:0)

方法Console.SetCursorPosition只获得2个int参数。 您指定了3个参数。我想你想说:

//the second comma was deleted
Console.SetCursorPosition(p.X, p.Y + j);

来源:http://msdn.microsoft.com/en-us/library/system.console.setcursorposition.aspx

答案 2 :(得分:0)

    Console.SetCursorPosition(p.X, p.Y, + j);

应该是

    Console.SetCursorPosition(p.X, p.Y + j);