I'm using Visual Studio 2010 with C#. Is there a concept in Windows Forms development of somehow linking a label with is text box? Something so that they move together as a unit? In the ASP.NET world, there is the AssociatedControlId property of the label control. I also think I remember MS Access form designer having some way of associating (or linking) labels with controls. Does this feature even exist in Visual Studio world?
If not, how do you group labels with controls such that if you move a text box you don't have to manually move the label also?
i think the best bet would be to use a GroupBox.
You can use extension methods to do it, follow example:
No there is not - at least with the out of the box controls. If you want this you could achieve it with a user control.
In general the winforms is not line driven in the same way as HTML is.
I 2nd @Neils answer of just creating a user control with a textbox in it. The panel can be used to group controls, but it can be pretty tedious if you have a lot of controls on the form.
If you want to support more than just textboxes, WinForms allows you to create your own designer. If you inherit your designer from the ParentControlDesigner class, you can drop any control you want into your custom label control.
This is my solution, using a
TableLayoutPanel
to place label and input control,Presetted some useful properties:
Preview
The code may need further wrap
Useage:
If you want to group labels with other controls (or group controls in general), then use the
System.Windows.Forms.Panel
control. The specific purpose of the Panel control is togroup collections of controls
.More information Panel Class (System.Windows.Forms)
If you want a higher degree of control (rather than using a Panel), then you could create a
UserControl
, that encapsulates aLabel
and aControl
.