如何得到窗体内按键 现有一窗体,在哪个事件中知道有按键,并得到按键,如按下F1键 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;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()); } }} if(e.KeyCode==Keys.B&&whetherSelected==false) //当鼠标玩者在走旗时,键盘玩者不得悔旗操作 label7_Click(sender,e); if(e.KeyCode==Keys.G&&whetherSelected==false) //当鼠标玩者在走旗时,键盘玩者不得悔旗操作 label8_Click(sender,e); if((e.KeyCode==Keys.ControlKey||e.KeyCode==Keys.Space||e.KeyCode==Keys.Enter) 老兄按照你的写法,还是不行窗体中有很多控件,还包括面板根本没有触发KeyDown该事件 这个单例模式有问题吗? .net问题 List<T>简单问题 Eval 错误,急.,........................ 诸位兄弟们,数据库连接失败,急等。。。 C# 如何调用已开发出来的 office 应用程序 怎么在程序里获取外网的IP地址啊 如何读取Visio控件中某个Shape的Custom Properties? 用C#写excel的问题 在WEB项目中,用DataGrid的问题。如何让表格的列名中,显示自己需要的字符串,而不是数据表中的列名?如解决问题可再加分。 下面三行程序有误,有哪位兄弟能改一下的呢? 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该事件