如何在c#.net中处理多个按键 [英] How to handle multiple key press in c#.net
本文介绍了如何在c#.net中处理多个按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在按Alt + F的同时打开表格.
为此该怎么做.如果有任何想法.
在此先谢谢您.
I want to open the form on key press of Alt+F.
What to do for this. If any one have any idea.
Thanks in advance.
推荐答案
看看这个 ^ ]
您需要订阅"KeyDown"事件.这是一个示例:
Hi,
you need to subscribe to the "KeyDown" event. Here is an example:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F && e.Modifiers == Keys.Alt)
{
//Show the form
}
}
用于Windows应用程序:
for windows Application:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt & e.KeyCode.ToString() == "F")
{
Form2 op = new Form2();
op.Show();
}
}
适用于Web应用程序:
for Web Application:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs"
Inherits="Default7" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
document.attachEvent('onkeyup', KeysShortcut);
// Now we need to implement the KeysShortcut
function KeysShortcut ()
{
if (event.keyCode == 17) // 17 keycode is for Left control key
{
document.getElementById('<%= button1.ClientID %>').click();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="a" runat="server"></asp:ScriptManager>
</div>
<div id="target" style="background-color: gray">This is a simple div</div>
<asp:Button ID="button1" runat="server" onclick="Button1_Click" />
</form>
</body>
</html>
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("About.aspx", false);
}
这篇关于如何在c#.net中处理多个按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文