我做了一个软件让他总是最前端显示。。
但是我需要一个功能。。就是点击这个软件的位置。会自动点击这个软件窗口的下面的那个窗口的相对位置
 而不是这个软件的位置不知道大家理解了没。。我找了好久都不知道如何实现

解决方案 »

  1.   

    通过调用ShowDialog()方法使窗体获得焦点
      

  2.   

    鼠标穿透?private const uint WS_EX_LAYERED = 0x80000;
            private const int WS_EX_TRANSPARENT = 0x20;
            private const int GWL_STYLE = -16;
            private const int GWL_EXSTYLE = -20;
            private const int LWA_ALPHA = 0x2;
            [DllImport("user32")]
            private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
            [DllImport("user32")]
            private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
            [DllImport("user32")]
            private static extern uint SetLayeredWindowAttributes(IntPtr hwnd, int crKey, int bAlpha, int dwFlags);        public void SetThrough()
            {
                uint temp = GetWindowLong(this.Handle, GWL_EXSTYLE);
                uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT);
                SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
            }
      

  3.   

    YEah 没错 就是穿透我试试 谢谢了
      

  4.   

    using System.Runtime.InteropServices;  
    #region API        [DllImport("user32.dll")]
            static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
            [Flags]
            enum MouseEventFlag : uint
            {
                Move = 0x0001,
                LeftDown = 0x0002,
                LeftUp = 0x0004,
                RightDown = 0x0008,
                RightUp = 0x0010,
                MiddleDown = 0x0020,
                MiddleUp = 0x0040,
                XDown = 0x0080,
                XUp = 0x0100,
                Wheel = 0x0800,
                VirtualDesk = 0x4000,
                Absolute = 0x8000
            }        #endregion//以上代码放在Class 任意处 mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
    //执行左键按下
     mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
    //执行左键松开//完成一个单击动作//之后执行以上代码便可模似鼠标单击一次 
      

  5.   

      void Form1_Click(object sender, EventArgs e)
            {
                int x = Control.MousePosition.X - this.Left;
                int y = Control.MousePosition.Y - this.Top;
                MessageBox.Show(x.ToString()+ ','+y.ToString());
              
            } 获取相对窗体的坐标