[英]Console Window Color, KeyUp, KeyDown and KeyPress Events
1) How do I change the background color so it will looks like this? 1)如何更改背景颜色,使其看起来像这样?
ConsoleColor only changes lines with text, I need to change the whole screen; ConsoleColor只更改带有文本的行,我需要更改整个屏幕; so don't say ConsoleColor.
所以不要说ConsoleColor。
2) How do I use KeyUp, KeyDown and KeyPress Event? 2)如何使用KeyUp,KeyDown和KeyPress事件? And how can I set different actions for different keys?
如何为不同的键设置不同的操作?
I found a lot of guides on these events, though I am just starting to use C#, so an explanation (and not just the code) will be preferred. 我发现了很多关于这些事件的指南,虽然我刚开始使用C#,所以首选解释(而不仅仅是代码)。
How do I change the background color
如何更改背景颜色
You have to clear the console after setting the BackgroundColor eg 您必须在设置BackgroundColor 后清除控制台,例如
Console.BackgroundColor = ConsoleColor.Blue;
Console.Clear();
How do I use KeyUp, KeyDown and KeyPress Event?
我如何使用KeyUp,KeyDown和KeyPress事件?
You would use Console.ReadKey and handle each key type eg 您将使用Console.ReadKey并处理每个密钥类型,例如
var input = Console.ReadKey();
switch (input.Key)
{
case ConsoleKey.LeftArrow:
// handle left arrow
break:
case ConsoleKey.RightArrow:
// handle right arrow
break;
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.