【发布时间】:2014-10-22 14:51:24
【问题描述】:
我有一个继承自 System.Windows.Forms.Control 的控件,它重写了 WndProc 函数以将消息传递给外部 DLL。函数看起来像
public class GraphicsPanel : Control
{
bool designMode;
EngineWrapper Engine;
public GraphicsPanel()
{
designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
this.SetStyle(ControlStyles.Selectable, true);
this.TabStop = true;
}
public void SetEngine(EngineWrapper Engine)
{
this.Engine = Engine;
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if(designMode) // Tried this option
return;
if (!designMode && Engine != null) // And this option
Engine.ProcessWindowMessage(m.Msg, m.WParam, m.LParam);
}
}
如果我在这个函数中提到了引擎,它会崩溃,因为在显示设计器时显然没有加载外部 DLL。我收到错误消息“无法加载文件或程序集“...”或其依赖项之一。
我当然应该补充一点,这段代码都是在运行时工作的,而不是在设计时工作的。每当我想使用设计器时,都必须注释掉两行引擎代码,这很烦人。
关于如何让设计器在包含这行代码时正确工作的任何建议。
【问题讨论】: