Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#控制台应用程序中绘制长方体和矩形_C#_Dialog_Drawing_Console Application - Fatal编程技术网

如何在C#控制台应用程序中绘制长方体和矩形

如何在C#控制台应用程序中绘制长方体和矩形,c#,dialog,drawing,console-application,C#,Dialog,Drawing,Console Application,我问两个相关的问题 1-如何将输出(如结果和消息)放入c#console应用程序的方框中。 2-如何在c#控制台应用程序中绘制矩形。感谢您提供的任何示例教程或建议 有C#的绑定(这可能是一个好的开始):如果您想自己编写,可以使用扩展ascii代码在控制台中绘制简单的形状 假设您只是指一个字符框,那么就可以了 private static void DrawABox( int x, int y, int width, int height,char Edge,string Message )

我问两个相关的问题

1-如何将输出(如结果和消息)放入c#console应用程序的方框中。

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

有C#的绑定(这可能是一个好的开始):

如果您想自己编写,可以使用扩展ascii代码在控制台中绘制简单的形状

假设您只是指一个字符框,那么就可以了

 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);
                }


            }

        }
private static void DrawABox(整数x、整数y、整数宽度、整数高度、字符边缘、字符串消息)
{
int LastIndex=0;
控制台。设置光标位置(x,y);
for(int h_i=0;h_i=Message.Length-1)
SEADINDEX=消息长度-1;
int newIndex=Message.LastIndexOf(“”,seaindex);
如果(新索引==-1)
newIndex=Message.Length-1;
string substr=Message.Substring(LastIndex,newIndex-LastIndex);
LastIndex=新索引;
控制台。设置光标位置(x+1,y+h_i);
Console.Write(substr);
}

对于(int w_i=0;w_i)来说,我的观点很好,乍一看,我想我明白了,谢谢,但我需要在这个问题上做更多的工作,以获得一个可靠的解决方案,然后我会发布它