0

I have a control inherited from System.Windows.Forms.Control which has the WndProc function overridden to pass the messages to an external DLL. The function looks like

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);
        }
}

If I have any mention of Engine in this function, it crashes because the external DLL apparently isn't loaded when the designer is displayed. I get the error message "Could not load file or assembly "..." or one of its dependencies.

I certainly should add that this code all works at run-time just not design-time. It's annoying having to comment out the two Engine lines of code whenever I want to use the designer.

Any advice for how to get the designer to work correctly while including this line of code.

enter image description here

Community
  • 1
  • 1
Russell Trahan
  • 783
  • 4
  • 34

2 Answers2

2

Do you need the WndProc to be executed in design-time? If not, you can try by adding a condition to the if:

bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
if (!designMode && Engine != null)
    ...

You will need System.ComponentModel namespace imported.

Detecting design mode from a Control's constructor

Community
  • 1
  • 1
thepirat000
  • 12,362
  • 4
  • 46
  • 72
0

I solved this by moving the Engine references to a different function. This is odd but it works.

    void PassMessage(Message m)
    {
        if (Engine != null)
            Engine.ProcessWindowMessage(m.Msg, m.WParam, m.LParam);
    }

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);

        if (!designMode)
            PassMessage(m);
    }
Russell Trahan
  • 783
  • 4
  • 34