c# - Winform Custom Control: Why Setter not called when used from Constructor? -


i have initial value property this:

    [category("main")]     [description("intial value")]     [defaultvalue(10)]     public int initialvalue     {         { return m_initialvalue; }         set {              m_initialvalue = value;             this.trackbar.value = this.m_initialvalue;         }     } 

so in constructor example:

        this.initialvalue = 10; 

to surprise when dragging custom control on form setter not called trackbar value not synchronized.

why ?

only when change property in dialog box setter called.

i decided take advice suggested in 1 of comments:

you can try take 2 minutes.

so did (it took 3 minutes), , i unable reproduce behavior described.

here exact steps followed:

  1. created new windows forms application.
  2. added new user control project.
  3. opened new user control in design view , added trackbar control (leaving trackbar control's properties set defaults).
  4. added following code user control class (exactly same posted above, addition of private field m_initialvalue omitted original example):

    public class usercontrol1 : usercontrol {    public usercontrol1()    {        initializecomponent();        this.initialvalue = 10;    }      [category("main")]    [description("intial value")]    [defaultvalue(10)]    public int initialvalue    {        { return m_initialvalue; }        set        {            m_initialvalue = value;            this.trackbar1.value = this.m_initialvalue;        }    }      int m_initialvalue; } 

  5. built project.
  6. opened default form (form1) created new project in design view.
  7. dragged user control had created (usercontrol1) out of toolbox automatically placed , onto surface of form.

the indicator on slider bar appeared way right side (the correct , expected position given default maximum value of 10). now, tell me: what doing differently?


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -