rt
如在窗体MouseMove事件,让鼠标在窗体中任何地方移动都能得到响应(现在是移到某个控件中就停止了响应);
如在窗体MouseDown按中某个子控件让窗体得到响应

解决方案 »

  1.   

    可以重写子控件的WndProc,然后处理鼠标的移动和按下消息.将其发给窗体
      

  2.   

    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:         
        {
             ...
        }                  
    }
      

  3.   

    可以让子控件的鼠标事件去执行的是窗体的鼠标事件,比方说这样写:
    this.label2.MouseMove +=new MouseEventHandler(this.Form1_MouseMove);
      

  4.   

    这是我刚写的个例子
    就是用我说的那个方法,实现起来蛮简单的:
    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();
    } }
    }