winform:怎么让窗体响应事件而非子控件 rt如在窗体MouseMove事件,让鼠标在窗体中任何地方移动都能得到响应(现在是移到某个控件中就停止了响应);如在窗体MouseDown按中某个子控件让窗体得到响应 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以重写子控件的WndProc,然后处理鼠标的移动和按下消息.将其发给窗体 protected override void WndProc(ref Message m) { base.WndProc (ref m); if(m.Msg == 0x84) { if ((IntPtr)2 == m.Result) { m.Result = (IntPtr)1; } } }//类似的 protected override void WndProc( ref Message m ) { switch(m.Msg) { case 0x84: { ... } } 可以让子控件的鼠标事件去执行的是窗体的鼠标事件,比方说这样写:this.label2.MouseMove +=new MouseEventHandler(this.Form1_MouseMove); 这是我刚写的个例子就是用我说的那个方法,实现起来蛮简单的:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Text.RegularExpressions;using System.Threading;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; private System.Windows.Forms.Label label2; private int i = 1; 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.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(8, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(80, 23); this.label1.TabIndex = 0; this.label1.Text = "label1"; // // label2 // this.label2.Dock = System.Windows.Forms.DockStyle.Bottom; this.label2.Location = new System.Drawing.Point(0, 89); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(292, 184); this.label2.TabIndex = 1; this.label2.Text = "label2"; this.label2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.KeyPreview = true; this.Name = "Form1"; this.Text = "Form1"; this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { i++; this.label1.Text = i.ToString(); } }} FileUpload1.PostedFile值的问题 搞不明白正则表达式相关类中的Captures属性 C#读取快捷方式的起始位置路径 怎样删除Gridview里被选中的一行记录? 属性重载不成功! 这个问题不知道怎么说,进来看看. 在ado.net中,关闭连接后,还可以执行存储过程吗???? 请教,WEB页里在数据库中读出文本该如何控制格式(急!) 泛型不能比较,怎么办? 如果我的程序最小化为一个notifyicon。。。我想用shift+z+x使其最大化。如何实现? ftp 中 list 得到的文件列表不全! 新手急问:共通类的问题,请问C#中有哪些共通类
{
base.WndProc (ref m);
if(m.Msg == 0x84)
{
if ((IntPtr)2 == m.Result)
{
m.Result = (IntPtr)1;
}
}
}//类似的
protected override void WndProc( ref Message m )
{
switch(m.Msg)
{
case 0x84:
{
...
}
}
this.label2.MouseMove +=new MouseEventHandler(this.Form1_MouseMove);
就是用我说的那个方法,实现起来蛮简单的:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text.RegularExpressions;
using System.Threading;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;
private System.Windows.Forms.Label label2;
private int i = 1; 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.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// label2
//
this.label2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.label2.Location = new System.Drawing.Point(0, 89);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(292, 184);
this.label2.TabIndex = 1;
this.label2.Text = "label2";
this.label2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.KeyPreview = true;
this.Name = "Form1";
this.Text = "Form1";
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
i++;
this.label1.Text = i.ToString();
} }
}