DesignMode broken - suggested path?

K

Kyjan

Greetings!

In doing some research, I've learned that some other people have had
problems with Me.DesignMode not working correctly when it's used in a
user control that is placed on another form. There was a suggestion...

Protected Shadows ReadOnly Property DesignMode() As Boolean
Get
If (MyBase.DesignMode) Then
Return True
Else
Dim parent As Control = Me.Parent
While Not (parent) Is Nothing
Dim site As ISite = parent.Site
If Not (site) Is Nothing AndAlso
site.DesignMode Then
Return True
End If
parent = parent.Parent
End While
Return False
End If
End Get
End Property

....but this suggestion does not work effectively. Does anyone know of
another way and/or a supplement to this recursive function that I am
not seeing? I've heard that you can use GetCurrentProcess, but that
didn't seem to work for me.

Thanks,

Kyjan
 
C

Cor Ligthert [MVP]

Kyjan,

I don't know if others understand this text but I don't.
In doing some research, I've learned that some other people have had
problems with Me.DesignMode not working correctly when it's used in a
user control that is placed on another form. There was a suggestion...
A user control can be placed on every form, therefore I have the idea that
you mean something else?

Cor
 
K

Kyjan

My apologies, I should have elaborated a little more.

I have created a user control that has some code that needs to run in
the Load event. When I compile the user control and then place the
user control on another form, because of the fact that the designer
actually instantiates the class, it runs the code in the Load event.
I'm trying to prevent that by testing the DesignMode property.
However, it's not working correctly because even though the UC might
not be in design mode, the form that the UC is on is in DesignMode.

Kyjan
 
D

DCraig

I would put your code into a public subroutine of the control and call it
from the load event of the form instead of the load event of the control -
assuming that will accomplish what you want. As you've found, you can't
rely on control events to happen when you think they should. In VS03 I've
had a lot of problems with user controls firing events at odd times and
repeatedly. It's a little more work, but it works for me.

hth;

DCraig.
 

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