[英]How do I remove the bitmap from a custom control in WinForms?
原理與嬉皮士的答案相同。 除了需要設置ImageBox.Image
屬性之外:
myImageBox.Image = null;
之所以有效,是因為以下代碼(摘自Hans對上一個問題的回答 ):
protected override void OnPaint(PaintEventArgs e) {
e.Graphics.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
if (mImage != null) e.Graphics.DrawImage(mImage, 0, 0);
base.OnPaint(e);
}
當您將控件的Image
屬性設置為null
,屬性設置器將強制控件重新繪制自身( this.Invalidate();
)。 當它重新繪制自身時,不會繪制任何圖像,因為負責繪制控件的OnPaint
方法會在繪制它之前驗證mImage != null
。
以下應該工作:
Form.BackgroundImage = null;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.