在子窗体Form2中加如下代码:
private void Form2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if((e.X >=this.ParentForm.Left) &&  (e.X<=this.ParentForm.Left+this.ParentForm.Width) &&
(e.Y>=this.ParentForm.Top) && 
(e.Y<=this.ParentForm.Top+this.ParentForm.Height))
{
//do your work
}
}

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication2
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;
    public static int myLeft=0;
    public static int myTop=0;
    public static int myWidth=0;
    public static int myHeight=0;
    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.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(192, 200);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(104, 32);
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(456, 273);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    //记录当前父窗体位置
    myLeft=this.Left;
    myTop=this.Top; 
    myWidth=this.Width;
    myHeight=this.Height; 
     
    Form2 myForm=new Form2();
    myForm.ShowDialog(); 
    }
    }
    }
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WindowsApplication2
    {
    /// <summary>
    /// Form2 的摘要说明。
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Timer timer1;
    private System.ComponentModel.IContainer components; public Form2()
    {
    //
    // 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.components = new System.ComponentModel.Container();
    this.label1 = new System.Windows.Forms.Label();
    this.timer1 = new System.Windows.Forms.Timer(this.components);
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(24, 16);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(240, 40);
    this.label1.TabIndex = 0;
    this.label1.Text = "label1";
    // 
    // timer1
    // 
    this.timer1.Enabled = true;
    this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
    // 
    // Form2
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 77);
    this.Controls.Add(this.label1);
    this.MaximizeBox = false;
    this.Name = "Form2";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "Form2";
    this.Load += new System.EventHandler(this.Form2_Load);
    this.ResumeLayout(false); }
    #endregion private void Form2_Load(object sender, System.EventArgs e)
    {
    label1.Text=Form1.myLeft.ToString()+"  "+Form1.myTop.ToString()+" "+Form1.myWidth.ToString()+" "+Form1.myHeight.ToString();     
    } private void timer1_Tick(object sender, System.EventArgs e)
    {
    if(((Cursor.Position.X<Form1.myLeft+Form1.myWidth)&&(Cursor.Position.X)>Form1.myLeft)&&((Cursor.Position.Y>Form1.myTop)&&(Cursor.Position.Y<Form1.myTop+Form1.myHeight)))
    MessageBox.Show("在父窗体内了!"); 

    }
    }
    }
      

  2.   

    我楼上那个代码只能是焦点在FORM2时的代码,我的是全局的代码
      

  3.   

    在主窗体的Enter或MouseEnter事件中监视就行
      

  4.   

    对不起我上面的代码不对。
    应该在主窗体中增加如下代码:
    private void Form1_MouseEnter(object sender, System.EventArgs e)
    {
       //your work
    }
      

  5.   

    能不能在Form_MouseMove事件中控制