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:
- created new windows forms application.
- added new user control project.
- opened new user control in design view , added
trackbarcontrol (leavingtrackbarcontrol's properties set defaults). added following code user control class (exactly same posted above, addition of private field
m_initialvalueomitted 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; }- built project.
- opened default form (
form1) created new project in design view. - 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
Post a Comment