gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:41:41 24 4
gpt4 key购买 nike

我问了 2 个相关问题。

1-我们如何将输出(例如结果和消息)放入 c# 控制台应用程序的框内。

2-我们如何在 C# 控制台应用程序中绘制矩形。感谢您提供任何示例教程或建议

最佳答案

假设您只是想要一个字符框,这就可以了。

 private static void DrawABox( int x, int y, int width, int height,char Edge,string Message )
{
int LastIndex =0 ;
Console.SetCursorPosition(x, y);
for ( int h_i = 0; h_i <= height ; h_i++ )
{
if ( LastIndex != -1 )
{
int seaindex = (LastIndex + ( width - 1) );
if(seaindex >= Message.Length -1 )
seaindex = Message.Length - 1;
int newIndex = Message.LastIndexOf(' ',seaindex);
if(newIndex == -1 )
newIndex = Message.Length - 1;
string substr = Message.Substring(LastIndex, newIndex - LastIndex);
LastIndex = newIndex;
Console.SetCursorPosition(x + 1, y + h_i);
Console.Write(substr);
}
for ( int w_i = 0; w_i <= width; w_i++ )
{

if ( h_i % height == 0 || w_i % width == 0 )
{
Console.SetCursorPosition(x + w_i, y + h_i);
Console.Write(Edge);
}


}

}

我编辑了代码以在他们的.您将需要在边界条件上做更多的工作。例如,消息中没有空格一个比框长的单词,但这应该足以让你开始。

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

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