2016-12-03 8 views
1

2つのボタンを含むフローティングボーダーレスフォームがあります。ユーザーがフォーム上でマウスを動かすと、FormBorderStyleはSizableToolWindowに変更され、タイマーを使用して設定された時間後に戻ります。これが起こると、フォームはタイトルバーとフォームエッジに対応するようにシフトします。私はこれを補うことができますが、起こったときにフォームのちらつきが元に戻される前にシフトされるようになります。クライアントエリアを移動せずにFormBorderStyleを変更する

既にウィンドウを元の位置に戻した後に、ウィンドウを更新する方法はありますか?

ここに私のシフトコードだ:ハンスアンパッサンが提案し、すでに透明フルスクリーンオーバーレイに表示されている私のClientRectangle領域の複製を作成するよう

 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

あなたのコードから、私は「これは」フォームと「変更」であると仮定いくつかの定数Rectangleです。場所の変更を追加して、コンテンツが動いていないように見えるようにすることもできます(ただし、スタイルに依存する可能性があります)。 –

+0

changeは、上端と左端が移動した距離を追跡するために使用されるサイズです(最初にフォームが境界線のみを失うように計算されます)。 FormのLeft&Topポジションを更新して、不足しているタイトルとフォームサラウンドを補う。それは動作しますが、フォームの動きのジッタを視覚的に見ることができます。 –

+1

ロケーションを変更しても問題は解決しませんか? (左上と少し左) –

答えて

0

私がやってしまいました。 My 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(); 
     } 
関連する問題