Detecting DesignMode

P

Paul W

I'm having trouble detecting whether my Control is in DesignMode. I'm
deriving a class from TreeView;

Public Class ExplorerView
Inherits TreeView

...

End Class

But when I want to see if it's in DesignMode, neither Me.DesignMode or
MyBase.DesignMode work, they always return False. The documentation states
that the class must implement ISite for DesignMode to return any other value
than False, so, I try to implement ISite, and I get errors stating I'm
trying to override a nonoverridable method. That says to me, TreeView is
already implenting ISite, but if that's true, why can't I get a meaningful
value from the DesignMode property. Any ideas? Thanks in advance.

Paul W
 
P

Paul W

Paul W said:
I'm having trouble detecting whether my Control is in DesignMode. I'm
deriving a class from TreeView;

Public Class ExplorerView
Inherits TreeView

...

End Class

But when I want to see if it's in DesignMode, neither Me.DesignMode or
MyBase.DesignMode work, they always return False. The documentation states
that the class must implement ISite for DesignMode to return any other value
than False, so, I try to implement ISite, and I get errors stating I'm
trying to override a nonoverridable method. That says to me, TreeView is
already implenting ISite, but if that's true, why can't I get a meaningful
value from the DesignMode property. Any ideas? Thanks in advance.

Paul W
OK, it looks as if I've solved this problem. The way the documentation
reads, leads you to believe that the way ISite is implemented is going to be
the problem, they fail to mention the more obvious. The code I needed to
run only if *not* in DesignMode was in the Constructor, which is typical in
this situation. However, this is to soon to determine if you're in
DesignMode, the control hasn't been sited yet, hence the False value.

The solution is to implement the ISupportInitialize interface. This
interface has two methods, BeginInit & EndInit. EndInit is called when the
component is finished initializing and is therefore the proper place to put
code that relies on the DesignMode property.

Paul W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top