How to visually subclass a combo box.

ALT

Member
Joined
Feb 23, 2006
Messages
9
Programming Experience
10+
First of all I am a beginner VB.net programmer (VB 2005 )
I want to visually subclass a combo box. I know how to subclass via code but my question is how to do with visually?

Want I mean is I want an icon to appear in the
toolbox so that I can drag my subclass combo box onto a form.


When done via code, the combo box is instantiated at run time. Therefore I can not via the IDE see the combo box at design time, which is why I am asking this question of visual subclassing.

It should be easy I assume, but somehow I’m missing the obvious.

Any help on this question would be greatly appreciated, thanks.
 
There is probably a more "correct" way to do it, but this is easy :)
1. Add new User Control, name it 'myComboBox'.
2. Click 'Show all files' in Solution Explorer, click '+' at the 'myComboBox', doubleclick the myComboBox.Designer.vb you now see to get the designer generated code.
3. The Usercontrol class now says it inherits from System.Windows.Forms.UserControl, change it to inherit from System.Windows.Forms.ComboBox.
4. Now you get an error on the AutoScaleMode line in InitializeComponent sub, just remove that line.
5. Rebuild and go to Designer View of your form, top of the toolbox is the myComboBox in UserControls to drag onto form.

Change the combobox UC and rebuild, and the instance on form will update also.
 
First of all Thanks! that does it.

The key for me was the line #2 "Click 'Show all files' in Solution Explorer, click..." At first I did know what you meant. I did not see any 'Show all files", but some clicking here, a hokey-pokey there and sure enough I was able to see the 'Show all button'

Follow up question:
I do see 'myComboBox' in the tool box now, but by any chance do you know how to get it to display the combobox icon, instead of an 'gear' Might there be some class property that I am not aware of?

Thanks again!
 
The 'Show all files' is one of the buttons in the toolstrip top of Solution Explorer, lucky you hit it..

I think the 'gear' symbolize all usercontrols by VS. Actually all the other controls in my Express just got an annoying 'document page' like icon.. so I thought the 'gear' was nice for a change :)
 
I swear for awhile it was not there ( the show all button ) or at least the tool tip was not, anyhow I'm off and running....:)
 
Back
Top