在运行时通过KeyBoard单击任意键打开表单 [英] Open Form By Click Any Key By KeyBoard At Run Time
问题描述
Hello Friends,
我有一个mdi主表单,其中有一些菜单。我做了一个表格,我没有在菜单中显示。我只是想通过键盘上的点击和键打开那个表单,比如alt + F6,Ctrl + F6就像是......
所以我想通过点击任意键来了解打开该表单的代码。我已经在主表单的按键事件中写了一个2行代码。
即....
Hello Friends,
I have a mdi main form in which there are some menus. i made a form which i was not show in that menus. i just want to open that form by click and key from keyboard like alt+F6, Ctrl+F6 like something...
so i want to know the code for open that form by click any key. i have already written a 2 line code in keypress event of my main form.
that is....
if (e.KeyChar == 63) // Ctrl + F6
{
Cotation ct = new Cotation();
ct.MdiParent = this;
ct.Show();
}
但它没有用......
我做错了什么?帮助我...
提前谢谢...
but it was not working...
what was i doing wrong? Help me for this...
Thanks in advance...
推荐答案
使用KeyUp而不是使用KeyDown。它应该工作。我试过了。以下代码片段应该这样做。
Instead of using KeyDown, use KeyUp. It shall work. I have tried it out. The following code snippet should do it.
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData.ToString().Equals("F6, Control"))
{
Cotation ct = new Cotation();
ct.MdiParent = this;
ct.Show();
}
}
希望这会有所帮助。
Hope this helps.
这篇关于在运行时通过KeyBoard单击任意键打开表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!