Add Controls to a Form - Windows Forms .NET (2024)

  • Article

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.

Important

The Desktop Guide documentation for .NET 7 and .NET 6 is under construction.

Add with Designer

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:

Add the control by double-clicking

When a control is double-clicked, it is automatically added to the current open form with default settings.

Add Controls to a Form - Windows Forms .NET (1)

Add the control by drawing

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.

Add Controls to a Form - Windows Forms .NET (2)

Add with code

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)

See also

Add Controls to a Form - Windows Forms .NET (2024)

FAQs

How can you add controls to a form? ›

Add the control by drawing

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.

How do I add dynamic controls in Windows form? ›

Add controls to the form
  1. Add the following code to add each object to the Controls array of the form at the end of Form1_Load : C# Copy. //Add controls to the form. this. Controls. Add(btnAdd); this. Controls. Add(txtBox); this. Controls. Add(lstBox); this. Controls. Add(chkBox); this. Controls. ...
  2. Save the project.
May 7, 2022

How do I add controls to a form in Visual Studio? ›

Add controls to your application
  1. Open Visual Studio. ...
  2. In the Windows Forms Designer, select the TableLayoutPanel you added in the previous tutorial. ...
  3. On the left side of the Visual Studio IDE, select the Toolbox tab. ...
  4. Double-click PictureBox to add a PictureBox control to your form.
Mar 29, 2024

How to add user control to Windows form C#? ›

Add a user control to a project
  1. In Visual Studio, find the Project Explorer pane. Right-click on the project and choose Add > User Control (Windows Forms).
  2. In the Name box, type a name for your user control. Visual Studio provides a default and unique name that you may use. Next, press Add.
Apr 19, 2024

Top Articles
Financial Advice Sought By A 13 Year Old Cryptocurrency Trader
John McAfee Is Bullish on Bitcoin, Blames JP Morgan’s Mike Bell for Big Dip
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Umn Biology
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 6521

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.