示例#1
0
 private void timer_Tick(object sender, EventArgs e)
 {
     if (IsIndent)
     {
         IntPtr vHandle = MemoryAddress.WindowFromPoint(Control.MousePosition);
         while (vHandle != IntPtr.Zero && vHandle != Handle)
         {
             vHandle = MemoryAddress.GetParent(vHandle);
         }
         if (vHandle == Handle) // 如果鼠标停留的窗体是本窗体,还原位置
         {
             if ((anchors & AnchorStyles.Left) == AnchorStyles.Left)
             {
                 Left = 0;
             }
             if ((anchors & AnchorStyles.Top) == AnchorStyles.Top)
             {
                 Top = 0;
             }
             if ((anchors & AnchorStyles.Right) == AnchorStyles.Right)
             {
                 Left = Screen.PrimaryScreen.Bounds.Width - Width;
             }
             if ((anchors & AnchorStyles.Bottom) == AnchorStyles.Bottom)
             {
                 Top = Screen.PrimaryScreen.Bounds.Height - Height;
             }
         }
         else if (mIsStop)
         {
             if ((anchors & AnchorStyles.Left) == AnchorStyles.Left)
             {
                 Left = 0;
             }
             if ((anchors & AnchorStyles.Top) == AnchorStyles.Top)
             {
                 Top = 0;
             }
             if ((anchors & AnchorStyles.Right) == AnchorStyles.Right)
             {
                 Left = Screen.PrimaryScreen.Bounds.Width - Width;
             }
             if ((anchors & AnchorStyles.Bottom) == AnchorStyles.Bottom)
             {
                 Top = Screen.PrimaryScreen.Bounds.Height - Height;
             }
             mIsStop       = false;
             timer.Enabled = false;
         }
         else // 隐藏起来
         {
             if ((anchors & AnchorStyles.Left) == AnchorStyles.Left)
             {
                 Left = -Width + OFFSET;
             }
             else if ((anchors & AnchorStyles.Top) == AnchorStyles.Top)
             {
                 Top = -Height + OFFSET;
             }
             else if ((anchors & AnchorStyles.Right) == AnchorStyles.Right)
             {
                 Left = Screen.PrimaryScreen.Bounds.Width - OFFSET;
             }
             else if ((anchors & AnchorStyles.Bottom) == AnchorStyles.Bottom)
             {
                 Top = Screen.PrimaryScreen.Bounds.Height - OFFSET;
             }
         }
     }
 }