469,622 Members | 2,139 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,622 developers. It's quick & easy.

Detecting DesignMode

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
Nov 20 '05 #1
1 2015

"Paul W" <no****@vbtips.net> wrote in message
news:u%******************@TK2MSFTNGP11.phx.gbl...
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
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Lecture Snoddddgrass | last post: by
1 post views Thread by Tiago Barbutti | last post: by
2 posts views Thread by Malleier Alfred | last post: by
29 posts views Thread by Charles Law | last post: by
2 posts views Thread by Simon Rigby | last post: by
2 posts views Thread by graeme g | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.