Events
17 Mar, 23 - 21 Mar, 23
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Most forms are designed by adding controls to the surface of the form to define a user interface (UI). A control is a component on a form used to display information or accept user input.
The primary way a control is added to a form is through the Visual Studio Designer, but you can also manage the controls on a form at run time through code.
Visual Studio uses the Forms Designer to design forms. There is a Controls pane which lists all the controls available to your app. You can add controls from the pane in two ways:
When a control is double-clicked, it is automatically added to the current open form with default settings.
Select the control by clicking on it. In your form, drag-select a region. The control will be placed to fit the size of the region you selected.
Controls can be created and then added to a form at run time with the form's Controls collection. This collection can also be used to remove controls from a form.
The following code adds and positions two controls, a Label and a TextBox:
Label label1 = new Label()
{
Text = "&First Name",
Location = new Point(10, 10),
TabIndex = 10
};
TextBox field1 = new TextBox()
{
Location = new Point(label1.Location.X, label1.Bounds.Bottom + Padding.Top),
TabIndex = 11
};
Controls.Add(label1);
Controls.Add(field1);
Dim label1 As New Label With {.Text = "&First Name",
.Location = New Point(10, 10),
.TabIndex = 10}
Dim field1 As New TextBox With {.Location = New Point(label1.Location.X,
label1.Bounds.Bottom + Padding.Top),
.TabIndex = 11}
Controls.Add(label1)
Controls.Add(field1)
.NET Desktop feedback feedback
.NET Desktop feedback is an open source project. Select a link to provide feedback:
Events
17 Mar, 23 - 21 Mar, 23
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register now