问题描述
- 未处理InvalidaOperationException
-
Object is Current in use elsewhere.
排错提示:如果在使用GetHdc方法后使用Graphic对象,请调用ReleaseHdc方法。获取此异常的常规帮助。自己写了一个PictureButton的控件,在e.Graphics.DrawImage出的异常
protected override void OnPaint(PaintEventArgs e) { if (image != null) // && (this.Enabled) { lock(image) { e.Graphics.DrawImage(image, this.ClientRectangle, 0, 0, image.Width, image.Height,
GraphicsUnit.Pixel, imgAttr);
}}
if (string.IsNullOrEmpty(this.Text)) { if (string.IsNullOrEmpty(this.txtBottom)) { e.Graphics.DrawString(txtTop, this.Font, brush, this.rectTxt, strFmtTxt); } else { e.Graphics.DrawString(txtTop, this.Font, brush, this.rectTop, strFmtTop); e.Graphics.DrawString(txtBottom, this.Font, brush, this.rectBottom, strFmtBottom); } } else { e.Graphics.DrawString(this.Text, this.Font, brush, this.rectTxt, strFmtTxt); } base.OnPaint(e); }
已尝试两种方法 均无效:1.跨线程访问的问题,加了InvokeRequre;2.加了GetHdc ReleaseHdc;
VS2005 C#
求助,谢谢!!!
时间: 2024-10-03 22:55:42