在控制台应用程序中定位和移动形状(console.write(“bla bla bla”);)

发布于 2024-11-29 07:20:23 字数 985 浏览 1 评论 0原文

我的控制台应用程序如下所示:

static void Main(string[] args)
{
    string Now = DateTime.Now.ToShortDateString();
    if (Now == "2011/08/12")
    {
        Console.Clear();
        Console.Write("Money..........");
        Console.Read();
    }
    else
    {
        int n = 6;

        var result = string.Join("\r\n", from i in Enumerable.Range(1, n)
                                         where i != 2
                                         let stars = Enumerable.Repeat('*', i)
                                         let indent = new string(' ', n - i)
                                         select indent + string.Join(" ", stars));

        Console.WriteLine(result);
        Console.Read();
    }
} 

上面的代码是用 c# 编写的

我的问题:
1-我们如何在控制台应用程序中找到一些形状示例,例如上面带有*的示例!
上面带有星星的例子太简单了/我正在寻找一些更好的形状,比如悬挂某人(只是为了好玩)
2-如何使用代码移动 console.write 窗口?
3-如何在 console.write 窗口内移动形状?
4-如何设置 consol.write 窗口定位?

提前致谢

my console application in like below :

static void Main(string[] args)
{
    string Now = DateTime.Now.ToShortDateString();
    if (Now == "2011/08/12")
    {
        Console.Clear();
        Console.Write("Money..........");
        Console.Read();
    }
    else
    {
        int n = 6;

        var result = string.Join("\r\n", from i in Enumerable.Range(1, n)
                                         where i != 2
                                         let stars = Enumerable.Repeat('*', i)
                                         let indent = new string(' ', n - i)
                                         select indent + string.Join(" ", stars));

        Console.WriteLine(result);
        Console.Read();
    }
} 

the upper codes are in c#

my questions :
1- how can we find some shape examples in console application like the upper example with *!
the upper example with stars is too simple / i am looking for some better shapes like hanging somebody (just for fun)
2- how can i move console.write window with code ?
3- how can i move shape inside console.write window ?
4- how can i set consol.write window positioning ?

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千纸鹤 2024-12-06 07:20:23

您是否查看过 MSDN http://msdn.microsoft.com/en- us/library/system.console.aspx

1 - 你必须自己计算出形状,享受吧。

这是一段执行某些操作的代码,但您的示例中已经有一些代码。

int pos = 0
int limit = 80
while (true)
{
    StringBuilder line  = new StringBuilder(limit);
    for(int i = 0; i < limit; i++)
    {
        if (i = pos)
        {
            line.Append("A");
        }
        else
        {
            line.Append(" ");
        }
    }
    Console.WriteLine(line.ToString());
    if (pos = (limit - 1))
    {
        pos = 0;
    }
    else
    {
        pos++;
    }
}

2 - 您可以使用 Console.WindowLeftConsole.WindowsTop 移动控制台窗口

3 - 形状在这里是错误的词和想法,您只能读写文本行。您可以通过使用字符 0 作为背景,将整行填充为“空白”,然后使用其他一些字符来表示您的移动形状的印象形状。请参阅上面的示例。

4 - 与 2 相同。

Have you looked at MSDN http://msdn.microsoft.com/en-us/library/system.console.aspx

1 - You will have to work out the shapes yourself, enjoy.

Here is a code that does somthing but you already have some in your example.

int pos = 0
int limit = 80
while (true)
{
    StringBuilder line  = new StringBuilder(limit);
    for(int i = 0; i < limit; i++)
    {
        if (i = pos)
        {
            line.Append("A");
        }
        else
        {
            line.Append(" ");
        }
    }
    Console.WriteLine(line.ToString());
    if (pos = (limit - 1))
    {
        pos = 0;
    }
    else
    {
        pos++;
    }
}

2 - You can move the console window with Console.WindowLeft and Console.WindowsTop

3 - Shape is the wrong word and idea here, you can only read and write lines of text. You could create the impression of a moving shape by using a char say 0 or as background, populating the whole line as "blank", Then use some other chars to represent your shape. See the example above.

4 - Same as 2.

小ぇ时光︴ 2024-12-06 07:20:23

要重新定位实际的控制台窗口,您需要使用 GetConsoleWindow (Win32 API) 执行 SetWindowPos,如 此处

[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

//    
SetWindowPos(GetConsoleWindow(), 0, x, y, 0, 0, SWP_NOSIZE);

关于在控制台窗口内部操作形状,请查看MonoCurses 。我不确定它是否适用于 Windows,但它相当先进(具有窗口、对话框、应用程序抽象和许多用于数据输入的小部件)

To relocate the actual console window, you'd need to do SetWindowPos with GetConsoleWindow (Win32 API) as described here.

[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

//    
SetWindowPos(GetConsoleWindow(), 0, x, y, 0, 0, SWP_NOSIZE);

On manipulating shapes inside the console window, have a look at MonoCurses. I'm not sure whether it works on Windows yet, but is quite advanced (having Window, Dialog, Application abstractions and a lot of widgets for data entry)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文