C# 如何暂停我的程序并等待 WinForm 中的键盘输入 [英] C# how do I pause my program and wait for keyboard input from within a WinForm

查看:25
本文介绍了C# 如何暂停我的程序并等待 WinForm 中的键盘输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# 2008 Winform 应用程序,我正处于循环中.我正在向用户显示一个日期,我希望他们告诉我这个日期所在的星期几.例如显示 6/22/2010,用户需要按 t.

I have a C# 2008 Winform application and I'm in the middle of a loop. I'm displaying a date to the user and I want them to tell me the day of the week that this date falls on. For example 6/22/2010 is displayed and the user needs to press t.

我遇到的问题是如何暂停我的应用程序并等待键盘输入?我想回应 Esc, m, t, w, h, f, s, u 仅此而已.所有其他按键都将被忽略.

What I'm stuck on is how do I pause my application and wait for keyboard input? I want to respond to Esc, m, t, w, h, f, s, u and nothing else. All other key presses will be ignored.

在控制台应用程序中,它将是 Console.ReadLine().但是我将如何在 Winform 应用程序中执行此操作?

In a console application it would be Console.ReadLine(). But how would I do this within a Winform application?

谢谢

推荐答案

你或许可以使用模态对话框...

You could perhaps use a modal dialog...

尝试在演示方面想出更好的解决方案...

Trying to think of a better solution in terms of presentation...

这篇关于C# 如何暂停我的程序并等待 WinForm 中的键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆