我有幾個自定義控件在圖像中被覆蓋,並且如果它們被拖出屏幕並重新打開,則圖像沒有被正確重新繪製。我已經爲這些不同的控件覆蓋了油漆覆蓋,並且它們似乎工作正常,但如果拖動屏幕一次又一次地拖動它們不能正確繪製。任何人都知道爲什麼會發生這種情況和/或解決方案?被屏蔽/遮擋後,自定義控件上的觸發重繪?
編輯:有些問題似乎存在問題,即使對話框的調整速度太快,而不僅僅是從屏幕上移開。他們開始看起來像他們已經被繪製在自己的頂部。哪種有道理,但我無法弄清楚如何治療它。
編輯2:這些是fourstates(懸停,單擊,正常,停用)自定義按鈕,所以我不認爲容器的是這個問題,我不認爲..?在OnPaint中的代碼是:
private void CQPButton_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(BackColor);
if (BackgroundImage != null)
e.Graphics.DrawImage(BackgroundImage, e.ClipRectangle);
if (Image != null)
{
RectangleF rect = new RectangleF();
rect.X = (float)((e.ClipRectangle.Width - Image.Size.Width)/2.0);
rect.Y = (float)((e.ClipRectangle.Height - Image.Size.Height)/2.0);
rect.Width = Image.Width;
rect.Height = Image.Height;
e.Graphics.DrawImage(Image, rect);
}
if (Text != null)
{
SizeF size = e.Graphics.MeasureString(this.Text, this.Font);
// Center the text inside the client area of the PictureButton.
e.Graphics.DrawString(this.Text,
this.Font,
new SolidBrush(this.ForeColor),
(this.ClientSize.Width - size.Width)/2,
(this.ClientSize.Height - size.Height)/2);
}
}
我試圖強迫重畫上各種事件,LocationChanged和移動嘗試和處理調整大小的問題,ClientSizeChanged嘗試和處理時,他們關閉屏幕,並沒有什麼是堅持。我不知道我錯過了什麼......
這可能有助於看到您的渲染代碼相關片段。 –
@JohnArlen - 添加了OnPaint事件和一些更多描述。 – trycatch