2016-12-03 37 views
1

我有一個包含兩個按鈕的浮動無邊界窗體。當用戶將鼠標移動到窗體上時,FormBorderStyle更改爲SizableToolWindow,然後使用計時器在設定的時間後返回。發生這種情況時,表單會移動以適應標題欄和窗體邊緣。但是,如果發生這種情況,我可以對此進行補償,因此在重新放置到位之前,您會看到閃爍的表格被移位。更改FormBorderStyle沒有客戶區域移動

有沒有什麼辦法可以阻止窗口刷新,直到我已經將它移回原位?

這裏是我的移動代碼:

 if (this.FormBorderStyle != FormBorderStyle.None) 
     { 
      // Suspend layout of Form 
      this.SuspendLayout(); 

      // Suspend layout of button controls 
      this.cbBlankDisplay.SuspendLayout(); 
      this.btnPurgeMessages.SuspendLayout(); 

      this.FormBorderStyle = FormBorderStyle.None; 
      this.Left += this.change.Width; 
      this.Top += this.change.Height; 

      // Resume layout of buttons and Form 
      this.btnPurgeMessages.ResumeLayout(); 
      this.cbBlankDisplay.ResumeLayout(); 
      this.ResumeLayout(); 
     } 
+1

從你的代碼,我認爲「這個」的形式和「變」是一些不變的矩形。您可以添加位置更改,使其看起來像內容不移動(儘管可能取決於樣式)。 –

+0

更改大小用於跟蹤頂部和左側移動的距離(首次計算表單失去其邊框)。然後,我更新表格的左側和頂部位置以彌補缺失的標題和表格環繞。它可以工作,但您可以直觀地看到移動窗體的抖動。 –

+1

地點變更沒有修復嗎? (稍微向上並離開?) –

回答

0

我落得這樣做漢斯·帕桑特建議和創造其顯示在一個已經透明全屏覆蓋我ClientRectangle區域的副本。 我的MouseLeave事件只是啓動計時器。

這是代碼在我的MouseEnter事件:

private void FloatingButtons_MouseEnter(object sender, EventArgs e) 
    { 
     if (this.FormBorderStyle != FormBorderStyle.SizableToolWindow) 
     { 
      if (this.Tag is Bitmap) 
      { 
       Owner.overlay.CreateGraphics().DrawImage(
        (Bitmap)this.Tag, 
        new Rectangle(
         Point.Add(this.Location, this.change), 
         this.ClientRectangle.Size), 
        new Rectangle(this.Location, this.ClientRectangle.Size), 
        GraphicsUnit.Pixel 
        ); 
      } 
      this.Hide(); 
      this.SuspendLayout(); 
      this.cbBlankDisplay.SuspendLayout(); 
      this.btnPurgeMessages.SuspendLayout(); 
      if (this.change.Height == 0) 
      { 
       this.FormBorderStyle = FormBorderStyle.SizableToolWindow; 
       Rectangle scrPosition = RectangleToScreen(this.ClientRectangle); 
       this.change.Width = (scrPosition.Left - this.Left); 
       this.change.Height = (scrPosition.Top - this.Top); 
      } 
      this.Left -= this.change.Width; 
      this.Top -= this.change.Height; 
      this.FormBorderStyle = FormBorderStyle.SizableToolWindow; 
      this.btnPurgeMessages.ResumeLayout(); 
      this.cbBlankDisplay.ResumeLayout(); 
      this.ResumeLayout(); 
      this.Show(); 
      if (this.Tag != null && this.Tag is Bitmap) 
      { 
       ((Bitmap)this.Tag).Dispose(); 
       this.Tag = null; 
       Overlay.performUpdate = true; 
      } 
     } 
    } 

這是我Timer_Tick事件代碼:

 if (this.FormBorderStyle != FormBorderStyle.None) 
     { 
      // Create a bitmap the size of my Form 
      Bitmap bmp = new Bitmap(this.Bounds.Width, this.Bounds.Height); 
      // Copy the form to the newly created Bitmap 
      this.DrawToBitmap(bmp, new Rectangle(Point.Empty, this.Bounds.Size)); 
      // Create a rectangle of the Location and Size of the ClientArea 
      Rectangle rect = new Rectangle((Point)this.change, this.ClientRectangle.Size); 
      // The Owner Form contains a class that already performs overlays on the screen 
      Owner.overlay.CreateGraphics().DrawImage(
       bmp, 
       new Rectangle(
        Point.Add(this.Location, this.change), 
        this.ClientRectangle.Size), 
       rect, 
       GraphicsUnit.Pixel 
       ); 
      // Store the Bitmap in the Tag for Disposal after being used 
      this.Tag = bmp; 

      // Now I can hide my Form and perform necessary changes 
      this.Hide(); 
      this.SuspendLayout(); 
      this.cbBlankDisplay.SuspendLayout(); 
      this.btnPurgeMessages.SuspendLayout(); 
      this.FormBorderStyle = FormBorderStyle.None; 
      this.Left += this.change.Width; 
      this.Top += this.change.Height; 
      this.btnPurgeMessages.ResumeLayout(); 
      this.cbBlankDisplay.ResumeLayout(); 
      this.ResumeLayout(); 
      this.Show(); 
     }