我落得這樣做漢斯·帕桑特建議和創造其顯示在一個已經透明全屏覆蓋我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();
}
從你的代碼,我認爲「這個」的形式和「變」是一些不變的矩形。您可以添加位置更改,使其看起來像內容不移動(儘管可能取決於樣式)。 –
更改大小用於跟蹤頂部和左側移動的距離(首次計算表單失去其邊框)。然後,我更新表格的左側和頂部位置以彌補缺失的標題和表格環繞。它可以工作,但您可以直觀地看到移動窗體的抖動。 –
地點變更沒有修復嗎? (稍微向上並離開?) –