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
9 Ways to Deal With High Mortgage Rates - Experian
Calculating the effect of price and mix changes on sales and margin | Business Growth | articles
Victor Spizzirri Linkedin
Www.1Tamilmv.cafe
Chambersburg star athlete JJ Kelly makes his college decision, and he’s going DI
How To Be A Reseller: Heather Hooks Is Hooked On Pickin’ - Seeking Connection: Life Is Like A Crossword Puzzle
Southeast Iowa Buy Sell Trade
라이키 유출
BULLETIN OF ANIMAL HEALTH AND PRODUCTION IN AFRICA
Waive Upgrade Fee
Erskine Plus Portal
Lantana Blocc Compton Crips
123Moviescloud
Turning the System On or Off
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
How do you like playing as an antagonist? - Goonstation Forums
Teenleaks Discord
Sport-News heute – Schweiz & International | aktuell im Ticker
TBM 910 | Turboprop Aircraft - DAHER TBM 960, TBM 910
Nine Perfect Strangers (Miniserie, 2021)
Conan Exiles: Nahrung und Trinken finden und herstellen
Exterior insulation details for a laminated timber gothic arch cabin - GreenBuildingAdvisor
Jeff Now Phone Number
Morristown Daily Record Obituary
Timeforce Choctaw
At&T Outage Today 2022 Map
Cain Toyota Vehicles
Mini Handy 2024: Die besten Mini Smartphones | Purdroid.de
Aliciabibs
Jayme's Upscale Resale Abilene Photos
1979 Ford F350 For Sale Craigslist
Hobby Lobby Hours Parkersburg Wv
Ezstub Cross Country
Kids and Adult Dinosaur Costume
The Venus Flytrap: A Complete Care Guide
Gyeon Jahee
Arcane Odyssey Stat Reset Potion
Orangetheory Northville Michigan
World Social Protection Report 2024-26: Universal social protection for climate action and a just transition
2023 Nickstory
Andrew Lee Torres
Postgraduate | Student Recruitment
Electric Toothbrush Feature Crossword
Satucket Lectionary
New Starfield Deep-Dive Reveals How Shattered Space DLC Will Finally Fix The Game's Biggest Combat Flaw
House For Sale On Trulia
Heat Wave and Summer Temperature Data for Oklahoma City, Oklahoma
Concentrix + Webhelp devient Concentrix
Www Ventusky
David Turner Evangelist Net Worth
Dcuo Wiki
Nfhs Network On Direct Tv
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.