469,954 Members | 1,827 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DesignMode broken - suggested path?

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

Jun 29 '06 #1
4 1282
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
Jun 29 '06 #2
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

Cor Ligthert [MVP] wrote:
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


Jun 29 '06 #3
Does anyone have any suggestions?

Kyjan

Jun 30 '06 #4
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.
"Kyjan" <Ho***********@gmail.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com...
Does anyone have any suggestions?

Kyjan

Jun 30 '06 #5

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
1 post views Thread by Paul W | last post: by
2 posts views Thread by Simon Rigby | last post: by
2 posts views Thread by graeme g | last post: by
3 posts views Thread by Giampaolo Rodola' | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.