.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

enter image description here

step 3: run project

result:

enter image description here

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.

enter image description here

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

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -