Saturday, January 16, 2010

Custom control in vb.net -- Just need a label and textbox in one control, editable at design time. How?

I need two controls... both are simply a textbox and a label control put together....





One needs to have them aligned vertically and the other horizontally.





the important thing that is required is that this control needs to have editable properties at design time.





I am making this control (with very limited programming experience) for our developers at work who are so strapped for manpower that they've handed this task to me... any guidance would be highly appreciated!





Everything I've found (i.e. MSDN article on making a control out of two existing controls) has been less than useful. ThanksCustom control in vb.net -- Just need a label and textbox in one control, editable at design time. How?
Type this in the top most part of the class.





' Use Friend declare if in the same namespace..


' Public or Friend declare exposes the Label and TextBox outside the class.


Public Withevents MyLabel as new Label ' Declares the Label


Public Withevents MyTextBox as new TextBox ' Declares a TextBox





' Place this in the control's Sub New() section


' To align them, use the dock property of the controls:


MyLabel.Dock = Top ' For Horizontal use Left


MyTextBox.Dock = Top ' For Horizontal use Left





' Add the Controls the your custom control


MyCustomControl.Controls.Add(MyLabel)


MyCustomControl.Controls.Add(MyTextBox鈥?br>




----


You can also use a LayOutTableControl, which is a little more complicated. But will have a desireable effect.


Any futher help, feel free to email me, I'll be glad to help.

No comments:

Post a Comment