[英]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.