c# - Calling InitializeComponent() twice in constructor -
so made simple class derived form
combobox
, button
.
in class's constructor initializecomponent()
gets fired twice follow. (just study purpose)
public form1() { initializecomponent(); initializecomponent(); // 1 more time } private void button1_click(object sender, eventargs e) { messagebox.show(combobox1.text); }
then whatever items in combobox1
click, combobox1.text
string.empty
.
the way solve problem seems call combobox1.dispose()
between 2 initializecomponent()
, , know why.
any appreciated.
thanks in advance.
look @ initializecomponents
in form1.designer.cs
.
if call twice, you'll have 2 combobox's. 1 may visible on can edit. other 1 (the second) 1 code refers to.
you "prove" introducing static field called counter
. edit initializecomponent
slightly, such moves combobox bit depending on counter
, set combobox.tag
counter
. finally, increment counter
.
however, you'll surely notice, problem of academic relevance. there's no benefit in calling initializecomponents
twice.
Comments
Post a Comment