How can I make a code in an event not execute in design time

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

    How can I make a code in an event not execute in design time

    Hi,
    How can I make a code in an event not execute in design time. I have a
    Baseform that has X code in the event "VisibleChanged ". All my forms
    inherit from this form. The code in this event always gets executed in
    design time, how do I avoid this??

    Regards
    Lucas


  • Eric Cadwell

    #2
    Re: How can I make a code in an event not execute in design time

    Your supposed to be able to use the DesignMode property.

    HTH;
    Eric Cadwell



    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: How can I make a code in an event not execute in design time

      Lucas,

      The Control class derives from Component. On the Component class, there
      is a property, DesignMode. If this property returns true, then your code is
      running in a designer. You can place a check around the firing of your
      event to see if your control is hosted in a designer, and not call it if
      that is the case.

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Lucas Sain" <lsain@lidersof t.com> wrote in message
      news:eJFjR4KnDH A.2732@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Hi,
      > How can I make a code in an event not execute in design time. I have a
      > Baseform that has X code in the event "VisibleChanged ". All my forms
      > inherit from this form. The code in this event always gets executed in
      > design time, how do I avoid this??
      >
      > Regards
      > Lucas
      >
      >[/color]


      Comment

      • Lucas Sain

        #4
        Re: How can I make a code in an event not execute in design time

        Thanks
        It worked great.

        regards
        Lucas

        "Eric Cadwell" <ecadwell@ns.in sight.com> wrote in message
        news:u%23DlscLn DHA.3256@tk2msf tngp13.phx.gbl. ..[color=blue]
        > Your supposed to be able to use the DesignMode property.
        >
        > HTH;
        > Eric Cadwell
        > http://www.origincontrols.com
        >
        >[/color]


        Comment

        • Lucas Sain

          #5
          Re: How can I make a code in an event not execute in design time

          Thanks
          It worked great.

          regards
          Lucas

          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
          message news:uthrOdLnDH A.1284@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Lucas,
          >
          > The Control class derives from Component. On the Component class,[/color]
          there[color=blue]
          > is a property, DesignMode. If this property returns true, then your code[/color]
          is[color=blue]
          > running in a designer. You can place a check around the firing of your
          > event to see if your control is hosted in a designer, and not call it if
          > that is the case.
          >
          > Hope this helps.
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >
          > "Lucas Sain" <lsain@lidersof t.com> wrote in message
          > news:eJFjR4KnDH A.2732@TK2MSFTN GP11.phx.gbl...[color=green]
          > > Hi,
          > > How can I make a code in an event not execute in design time. I have[/color][/color]
          a[color=blue][color=green]
          > > Baseform that has X code in the event "VisibleChanged ". All my forms
          > > inherit from this form. The code in this event always gets executed in
          > > design time, how do I avoid this??
          > >
          > > Regards
          > > Lucas
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Sean J Donovan

            #6
            Re: How can I make a code in an event not execute in design time

            Lucas Sain wrote:[color=blue]
            > Hi,
            > How can I make a code in an event not execute in design time. I have a
            > Baseform that has X code in the event "VisibleChanged ". All my forms
            > inherit from this form. The code in this event always gets executed in
            > design time, how do I avoid this??
            >
            > Regards
            > Lucas
            >
            >[/color]

            Hold on, DesignMode isn't reliable.

            If you have a component within a component, the DesignMode property on
            the embedded component is **always** wrong (ie. false within the designer).

            Instead, use the following, it'll save a lot of pain:

            // If this returns NULL, we're in DesignMode.
            if ( System.Reflecti on.Assembly.Get EntryAssembly() == null )
            {
            // We're in DesignMode.
            }

            Get into the habit of using this, and NOT the DesignMode property.

            An alternative is to check the name of the entry assembly. If you're in
            VS.NET, this will return [devenv.exe]. I prefer the above.

            If you think this is suspect, do a quick check on Google, there are some
            postings out there on the topic.

            Sean

            Comment

            • Eric Cadwell

              #7
              Re: How can I make a code in an event not execute in design time

              > Hold on, DesignMode isn't reliable.

              I can vouch for DesignMode not being accurate, but I thought it was based on
              me trying to use it in the Control's constructor.

              The docs also state the following:
              'The design mode indicator is stored in the ISite; therefore, if the
              Component does not have an ISite associated with it, this property is always
              false.'

              -Eric


              Comment

              • Lucas Sain

                #8
                Re: How can I make a code in an event not execute in design time

                Sean,

                Thanks will use your sugestion instead.

                Regards
                Lucas
                "Sean J Donovan" <sdonovan_uk@ya hoo.com> wrote in message
                news:OYVwL7MnDH A.976@tk2msftng p13.phx.gbl...[color=blue]
                > Lucas Sain wrote:[color=green]
                > > Hi,
                > > How can I make a code in an event not execute in design time. I have[/color][/color]
                a[color=blue][color=green]
                > > Baseform that has X code in the event "VisibleChanged ". All my forms
                > > inherit from this form. The code in this event always gets executed in
                > > design time, how do I avoid this??
                > >
                > > Regards
                > > Lucas
                > >
                > >[/color]
                >
                > Hold on, DesignMode isn't reliable.
                >
                > If you have a component within a component, the DesignMode property on
                > the embedded component is **always** wrong (ie. false within the[/color]
                designer).[color=blue]
                >
                > Instead, use the following, it'll save a lot of pain:
                >
                > // If this returns NULL, we're in DesignMode.
                > if ( System.Reflecti on.Assembly.Get EntryAssembly() == null )
                > {
                > // We're in DesignMode.
                > }
                >
                > Get into the habit of using this, and NOT the DesignMode property.
                >
                > An alternative is to check the name of the entry assembly. If you're in
                > VS.NET, this will return [devenv.exe]. I prefer the above.
                >
                > If you think this is suspect, do a quick check on Google, there are some
                > postings out there on the topic.
                >
                > Sean
                >[/color]


                Comment

                Working...