如何监视一个窗体是否发生点击或移动事件?我点击这个窗体或者之上的控件,或者移动这个窗体的位置,或者改变窗体的大小,将被认为该窗体处于活动状态.请问,C#有相关的事件吗?

解决方案 »

  1.   

            [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)]
            public static extern IntPtr GetForegroundWindow();  //获得当前活动窗体的句柄        [DllImport("user32.dll")]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    private IntPtr xHandle1;
    private IntPtr xHandle2;
                xHandle1 = FindWindow(null, "你监视的窗口的名称");
                xHandle2 = GetForegroundWindow();            //如果xHandle1和xHandle2相等,说明你监视的窗口正处于活动状态。不相等......没测试,你自己试试看
      

  2.   

    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            [DllImport("user32.dll")]  //需添加using System.Runtime.InteropServices
            public static extern bool ReleaseCapture();
            [DllImport("user32.dll")]
            public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
            public const int WM_SYSCOMMAND = 0x0112;
            public const int SC_MOVE = 0xF010;
            public const int HTCAPTION = 0x0002;   
     
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
            }
        }
    }这个是窗体移动就返回消息的