Design time problems

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

    Design time problems

    Is there any boolean flag set during design time that a UserControl can test
    to see whether to run code that only works during runtime (because of
    complicated initialization) ?

    Like this:

    public class MyControl : UserControl {
    public MyControl() {
    InitializeCompo nent();
    if (!System.Compon entModel.Design .MagicClass.IsD esignTime)
    DoSomethingUnsa feAtDesignTime( );
    }
    }

    Otherwise, I can't put my control on my form with the designer, which is
    mighty annoyin'.

    Chris


  • Rob Windsor

    #2
    Re: Design time problems

    Hi Chris,

    The UserControl has a Boolean property called DesignMode you can check.

    --
    Rob Windsor
    G6 Consulting
    Toronto, Canada


    "Chris Capel" <chris@ibanktec h.net> wrote in message
    news:uDLsajHeDH A.892@TK2MSFTNG P12.phx.gbl...[color=blue]
    > Is there any boolean flag set during design time that a UserControl can[/color]
    test[color=blue]
    > to see whether to run code that only works during runtime (because of
    > complicated initialization) ?
    >
    > Like this:
    >
    > public class MyControl : UserControl {
    > public MyControl() {
    > InitializeCompo nent();
    > if (!System.Compon entModel.Design .MagicClass.IsD esignTime)
    > DoSomethingUnsa feAtDesignTime( );
    > }
    > }
    >
    > Otherwise, I can't put my control on my form with the designer, which is
    > mighty annoyin'.
    >
    > Chris
    >
    >[/color]


    Comment

    • Chris Capel

      #3
      Re: Design time problems

      Well, DUH, Chris. How did you miss that?

      Hehe.

      Chris

      "Rob Windsor" <rwindsor@NO.MO RE.SPAM.bigfoot .com> wrote in message
      news:uzmkv6HeDH A.2080@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Hi Chris,
      >
      > The UserControl has a Boolean property called DesignMode you can check.
      >
      > --
      > Rob Windsor
      > G6 Consulting
      > Toronto, Canada
      >
      >[/color]


      Comment

      • Chris Capel

        #4
        Re: Design time problems

        > The UserControl has a Boolean property called DesignMode you can check.

        Strangely enough, this doesn't work at all. Example:

        using System;
        using System.Windows. Forms;

        namespace Something {
        public class MyUserControl : System.Windows. Forms.UserContr ol {
        public MyUserControl() {
        if (DesignMode)
        MessageBox.Show ("Hi, I'm in design mode.");
        else
        MessageBox.Show ("Sorry, but no design mode :-(");
        }
        }
        }

        If you place this in a code file in a project, load the designer for it (to
        register it with the design-time environment) and then try to drag it on a
        form, it shows a message box saying "Sorry, but not design mode :-(".
        Strange.

        Chris


        Comment

        • Rob Windsor

          #5
          Re: Design time problems

          Hi Chris,

          It appears that the property dosen't get set until after the constructor
          completes. The container (in this case the form) has to interact with the
          control's ISite interface and I'm not sure at what point of the control
          construction phase that happens. Anyway, if you put your if statement in the
          contol's Load event it will work properly.

          --
          Rob Windsor
          G6 Consulting
          Toronto, Canada


          "Chris Capel" < > wrote in message
          news:eIoODVIeDH A.1752@TK2MSFTN GP10.phx.gbl...[color=blue][color=green]
          > > The UserControl has a Boolean property called DesignMode you can check.[/color]
          >
          > Strangely enough, this doesn't work at all. Example:
          >
          > using System;
          > using System.Windows. Forms;
          >
          > namespace Something {
          > public class MyUserControl : System.Windows. Forms.UserContr ol {
          > public MyUserControl() {
          > if (DesignMode)
          > MessageBox.Show ("Hi, I'm in design mode.");
          > else
          > MessageBox.Show ("Sorry, but no design mode :-(");
          > }
          > }
          > }
          >
          > If you place this in a code file in a project, load the designer for it[/color]
          (to[color=blue]
          > register it with the design-time environment) and then try to drag it on a
          > form, it shows a message box saying "Sorry, but not design mode :-(".
          > Strange.
          >
          > Chris
          >
          >[/color]


          Comment

          Working...