System.ComponentModel.Win32Exception:操作成功完成
问题描述:
我创建了一个窗体,其中包含多个面板以使用C#显示图形。System.ComponentModel.Win32Exception:操作成功完成
try
{
if (myBuffer != null)
myBuffer.Dispose();
myBuffer = currentContext.Allocate(this.panel1.CreateGraphics(), this.panel1.DisplayRectangle);
}
catch (Win32Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
这是我正在使用的代码。
我得到这个错误System.ComponentModel.Win32Exception:操作完成成功,同时使窗口从最小化状态最大化。
答
BufferedGraphicsContext类是应该在内部进行的实现细节。它没有足够的灵活性来创造一个隐形控制的错误。很明显,它的异常报告还没有被很好地调试,对于没有经常受到错误影响的代码并不罕见。
显然你正在这样做双缓冲面板控件,它们不是默认的。只需创建自己的控件,派生自Panel。为您的项目添加一个新类并粘贴下面显示的代码。编译并将添加到工具箱顶部的新控件拖放到表单上,替换现有的控件。
using System;
using System.Windows.Forms;
class BufferedPanel : Panel {
public BufferedPanel() {
this.DoubleBuffered = true;
}
}