现有一窗体,在哪个事件中知道有按键,并得到按键,如按下F1键
解决方案 »
- 在Oracle 10g和VS2010间如何使用ODP.net开发?
- 技术咨询
- 新手求救,Process 里怎么加入 一个执行的函数或线程
- 高手救命!!异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误,
- 关于编写一个windons服务的问题,很棘手!!!
- 求助:红外端口编程中,使用程序打不开端口。
- 请问用C#怎么更新数据库中的数据?
- 请教~ winform(C#编写) datagrid怎样分页~~ webform好容易啊~
- 这个关于多线程的异常,如何处理
- 在c#中如何打印报表
- 下面三行程序有误,有哪位兄弟能改一下的呢?
- datetime类型比较生日?
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication3
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(96, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 25);
this.label1.TabIndex = 0;
this.label1.Text = "请按键";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.KeyPreview = true;
this.Name = "Form1";
this.Text = "Form1";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show(e.KeyCode.ToString());
}
}
}
label7_Click(sender,e);
if(e.KeyCode==Keys.G&&whetherSelected==false) //当鼠标玩者在走旗时,键盘玩者不得悔旗操作
label8_Click(sender,e);
窗体中有很多控件,还包括面板
根本没有触发KeyDown该事件