DesignMode broken - suggested path?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kyjan

    #1

    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.DesignM ode) 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 GetCurrentProce ss, but that
    didn't seem to work for me.

    Thanks,

    Kyjan

  • Cor Ligthert [MVP]

    #2
    Re: DesignMode broken - suggested path?

    Kyjan,

    I don't know if others understand this text but I don't.[color=blue]
    >
    > 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...
    >[/color]
    A user control can be placed on every form, therefore I have the idea that
    you mean something else?

    Cor


    Comment

    • Kyjan

      #3
      Re: DesignMode broken - suggested path?

      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:[color=blue]
      > Kyjan,
      >
      > I don't know if others understand this text but I don't.[color=green]
      > >
      > > 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...
      > >[/color]
      > A user control can be placed on every form, therefore I have the idea that
      > you mean something else?
      >
      > Cor[/color]

      Comment

      • Kyjan

        #4
        Re: DesignMode broken - suggested path?

        Does anyone have any suggestions?

        Kyjan

        Comment

        • DCraig

          #5
          Re: DesignMode broken - suggested path?

          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" <HolySaphAngel@ gmail.com> wrote in message
          news:1151674592 .811298.203450@ y41g2000cwy.goo glegroups.com.. .[color=blue]
          > Does anyone have any suggestions?
          >
          > Kyjan
          >[/color]


          Comment

          Working...