gpt4 book ai didi

c# - 如何在控制台应用程序中绘制矩形?

转载 作者:行者123 更新时间:2023-12-02 02:53:06 26 4
gpt4 key购买 nike

我需要在 C# 控制台应用程序中并使用扩展 ASCII 绘制一个矩形,内部有一个数字。我该怎么办?

这是一个演示。

最佳答案

public class ConsoleRectangle
{
private int hWidth;
private int hHeight;
private Point hLocation;
private ConsoleColor hBorderColor;

public ConsoleRectangle(int width, int height, Point location, ConsoleColor borderColor)
{
hWidth = width;
hHeight = height;
hLocation = location;
hBorderColor = borderColor;
}

public Point Location
{
get { return hLocation; }
set { hLocation = value; }
}

public int Width
{
get { return hWidth; }
set { hWidth = value; }
}

public int Height
{
get { return hHeight; }
set { hHeight = value; }
}

public ConsoleColor BorderColor
{
get { return hBorderColor; }
set { hBorderColor = value; }
}

public void Draw()
{
string s = "╔";
string space = "";
string temp = "";
for (int i = 0; i < Width; i++)
{
space += " ";
s += "═";
}

for (int j = 0; j < Location.X ; j++)
temp += " ";

s += "╗" + "\n";

for (int i = 0; i < Height; i++)
s += temp + "║" + space + "║" + "\n";

s += temp + "╚";
for (int i = 0; i < Width; i++)
s += "═";

s += "╝" + "\n";

Console.ForegroundColor = BorderColor;
Console.CursorTop = hLocation.Y;
Console.CursorLeft = hLocation.X;
Console.Write(s);
Console.ResetColor();
}
}

关于c# - 如何在控制台应用程序中绘制矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6006618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com