.net - Why is New() firing twice on my inherited controls? (winforms) -
step 1: create inhered control class
public class test_control inherits listbox public sub new() items.add("test") end sub end class
step 2: drag class form in designer
step 3: run project
result:
why happening?! stumped here.. have googled , googled , cannot find solution or answer this.
this causing major issues me. trying add initial "select one..." option every newly created combobox. same thing happens every inherited control class, regardless of control type (textbox/combobox/listbox/etc).
same thing happens if use message box within new(). 2 message boxes appear run application.
you need tell designer not serialize items collection:
public class test_control inherits listbox public sub new() items.add("test") end sub <designerserializationvisibility(designerserializationvisibility.hidden)> _ public shadows readonly property items listbox.objectcollection return mybase.items end end property end class
as far 2 message boxes go, messageboxes not debugging tool. getting winforms designer calling new while runtime calling new, (or that).
Comments
Post a Comment