Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Designer calls to class constructor several times!

Designer calls to class constructor several times!

Scheduled Pinned Locked Moved C#
questiondesign
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lexa1983
    wrote on last edited by
    #1

    I have a control inherited from ComboBox. In constructor I add some items. Now, when my control is have been putted onto form designed calls to constructor and item collection is automatically updates. How can I prevent this action, some directive or attribute that tells to designer not to call to constructor during the design time?

    J 1 Reply Last reply
    0
    • L Lexa1983

      I have a control inherited from ComboBox. In constructor I add some items. Now, when my control is have been putted onto form designed calls to constructor and item collection is automatically updates. How can I prevent this action, some directive or attribute that tells to designer not to call to constructor during the design time?

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Please see this page[^] for information about how to write design-time aware code. Also, the designer will always call the default constructor (i.e. the constructor that takes zero parameters). If you want to create a constructor that gets called only by your code, create a second constructor that takes a parameter.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Cops & Robbers Judah Himango

      -- modified at 13:30 Thursday 15th September, 2005

      L 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Please see this page[^] for information about how to write design-time aware code. Also, the designer will always call the default constructor (i.e. the constructor that takes zero parameters). If you want to create a constructor that gets called only by your code, create a second constructor that takes a parameter.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Cops & Robbers Judah Himango

        -- modified at 13:30 Thursday 15th September, 2005

        L Offline
        L Offline
        Lexa1983
        wrote on last edited by
        #3

        There is a lot of information there... unfortunately I have not found what I need, but thanks. Declare additional constructor with different from void parameters will be not so "right" way. It must be something that resolves this problem...

        J 1 Reply Last reply
        0
        • L Lexa1983

          There is a lot of information there... unfortunately I have not found what I need, but thanks. Declare additional constructor with different from void parameters will be not so "right" way. It must be something that resolves this problem...

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          If your control inherits from System.ComponentModel.Component (or System.Control, which inherits from System.ComponentModel.Component), then you can get the value from the protected DesignMode property to indicate whether you're in design mode.

          public class MyControl : Control
          {
          public MyControl()
          {
          // in design mode?
          bool designMode = this.DesignMode;
          }
          }

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Cops & Robbers Judah Himango

          L 1 Reply Last reply
          0
          • J Judah Gabriel Himango

            If your control inherits from System.ComponentModel.Component (or System.Control, which inherits from System.ComponentModel.Component), then you can get the value from the protected DesignMode property to indicate whether you're in design mode.

            public class MyControl : Control
            {
            public MyControl()
            {
            // in design mode?
            bool designMode = this.DesignMode;
            }
            }

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: Cops & Robbers Judah Himango

            L Offline
            L Offline
            Lexa1983
            wrote on last edited by
            #5

            thanks :) that is exactly what I need

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups