-1

我有一个类可以创建一个边框上具有不同颜色的 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(' ');
            }
        }
    }

}

关于我做错了什么的任何想法?

4

3 回答 3

0

您的 Console.SetCursorPosition 应该如下所示

Console.SetCursorPosition(int Left, int Top);
于 2013-02-11T09:00:02.997 回答
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

于 2013-02-11T09:02:54.420 回答
0
    Console.SetCursorPosition(p.X, p.Y, + j);

应该

    Console.SetCursorPosition(p.X, p.Y + j);
于 2013-02-11T09:03:12.553 回答