【发布时间】:2011-04-21 00:13:38
【问题描述】:
我问了两个相关的问题。
1-我们如何将输出(例如结果和消息)放入 c# 控制台应用程序的框内。
2-我们如何在 c# 控制台应用程序中绘制矩形。感谢您提供任何示例教程或建议
【问题讨论】:
标签: c# dialog drawing console-application
我问了两个相关的问题。
1-我们如何将输出(例如结果和消息)放入 c# 控制台应用程序的框内。
2-我们如何在 c# 控制台应用程序中绘制矩形。感谢您提供任何示例教程或建议
【问题讨论】:
标签: c# dialog drawing console-application
有用于 C# 的 curses 绑定(这可能是一个好的开始):http://curses-sharp.sourceforge.net/
【讨论】:
如果你想自己写,你可以使用扩展的 ascii 代码在控制台中绘制简单的形状。 Extended AScii Table
【讨论】:
假设你的意思是一个字符框,这就可以了。
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);
}
}
}
我编辑了代码以在其中添加一条消息。您将需要在边界条件上做更多的工作。例如,消息中没有空格,一个比方框长的词,但这应该足以让你开始。
【讨论】: