在控制台应用程序中定位和移动形状(console.write(“bla bla bla”);)
我的控制台应用程序如下所示:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否查看过 MSDN http://msdn.microsoft.com/en- us/library/system.console.aspx
1 - 你必须自己计算出形状,享受吧。
这是一段执行某些操作的代码,但您的示例中已经有一些代码。
2 - 您可以使用
Console.WindowLeft
和Console.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.
2 - You can move the console window with
Console.WindowLeft
andConsole.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
oras background, populating the whole line as "blank", Then use some other chars to represent your shape. See the example above.
4 - Same as 2.
要重新定位实际的控制台窗口,您需要使用
GetConsoleWindow
(Win32 API) 执行SetWindowPos
,如 此处。关于在控制台窗口内部操作形状,请查看MonoCurses 。我不确定它是否适用于 Windows,但它相当先进(具有窗口、对话框、应用程序抽象和许多用于数据输入的小部件)
To relocate the actual console window, you'd need to do
SetWindowPos
withGetConsoleWindow
(Win32 API) as described here.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)