如何实现按F5响应button1 如何实现按F5 响应button1 事件??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 WINFORM??代码还是 思路??给个思路吧找到 BTN1的 键盘DOWN事件然后获取 键盘上的按键是F5的时候 委托 执行BTN1的CLICK事件 在KeyPress事件里面判断点击的是否是F5键,是的话执行button1事件 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication18{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("我就是看看按F5行不行"); } private void Form1_KeyUp(object sender, KeyEventArgs e) { //判断是否按下的是F5 if (e.KeyCode ==Keys.F5) { //委托 增加BTN的点击事件 this.KeyUp +=new KeyEventHandler(button1_Click); //相应的 去除BTN的点击事件 否则 连续按F5 会增加委托事件 this.KeyUp -= new KeyEventHandler(button1_Click); } } private void Form1_Load(object sender, EventArgs e) { //Form 是否注册 键盘事件 默认为FALSE this.KeyPreview = true; } }} 2楼说的 是KEYDOWN 我下面是用的KEYUP 如果项目全局用的话注册热键比较好[DllImport("user32")] public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk); [DllImport("user32")] public static extern bool UnregisterHotKey(IntPtr hWnd, int id); protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x0312: if (m.WParam.ToString() == "123") { this.Hide(); } else if (m.WParam.ToString() == "456") { this.Visible = true; } break; } base.WndProc(ref m); } private void BookShelf_Load(object sender, EventArgs e) { //register:press [H] key to hide,and press [S] key to show RegisterHotKey(this.Handle, 123, 0, Keys.H); RegisterHotKey(this.Handle, 456, 0, Keys.S); } private void BookShelf_FormClosed(object sender, FormClosedEventArgs e) { //unregister the hide/show hotkey UnregisterHotKey(this.Handle, 123); UnregisterHotKey(this.Handle, 456); } 用什么建不好,你怎么偏要去用F5,本来WINDOS就响应这个键了,换一个嘛 怎么在BS程序中嵌入CS的窗体 C#如何调用C++写的DLL接口 C# 关于API函数PostMessage()的鼠标单击坐标参数lParam 多线程的进度条 如何通过C#实现如图所示的智能录入功能? 能不能获取SQL server企业管理器里生成的脚本 Arraylist抛出'System.InvalidOperationException‘ 求助:winform下的listbox问题 Help,c#debug时的异常 怎样在c#中载入摄像头的视频? Intptr的释放问题 sql 列行转换
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("我就是看看按F5行不行");
} private void Form1_KeyUp(object sender, KeyEventArgs e)
{
//判断是否按下的是F5
if (e.KeyCode ==Keys.F5)
{
//委托 增加BTN的点击事件
this.KeyUp +=new KeyEventHandler(button1_Click);
//相应的 去除BTN的点击事件 否则 连续按F5 会增加委托事件
this.KeyUp -= new KeyEventHandler(button1_Click);
}
} private void Form1_Load(object sender, EventArgs e)
{
//Form 是否注册 键盘事件 默认为FALSE
this.KeyPreview = true;
}
}
}
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk); [DllImport("user32")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id); protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0312:
if (m.WParam.ToString() == "123")
{
this.Hide();
}
else if (m.WParam.ToString() == "456")
{
this.Visible = true;
}
break;
}
base.WndProc(ref m); } private void BookShelf_Load(object sender, EventArgs e)
{
//register:press [H] key to hide,and press [S] key to show
RegisterHotKey(this.Handle, 123, 0, Keys.H);
RegisterHotKey(this.Handle, 456, 0, Keys.S);
} private void BookShelf_FormClosed(object sender, FormClosedEventArgs e)
{
//unregister the hide/show hotkey
UnregisterHotKey(this.Handle, 123);
UnregisterHotKey(this.Handle, 456);
}