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.

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)
Top Articles
How To Cook With Honey BBQ Sauce - Allegro Marinade
What Is Offshore Investing | Investments - HSBC Expat
San Angelo, Texas: eine Oase für Kunstliebhaber
Joi Databas
Otterbrook Goldens
T&G Pallet Liquidation
Midway Antique Mall Consignor Access
Espn Expert Picks Week 2
Hillside Funeral Home Washington Nc Obituaries
Oscar Nominated Brings Winning Profile to the Kentucky Turf Cup
Pittsburgh Ultra Advanced Stain And Sealant Color Chart
2024 U-Haul ® Truck Rental Review
Labor Gigs On Craigslist
Huge Boobs Images
180 Best Persuasive Essay Topics Ideas For Students in 2024
Apus.edu Login
Xxn Abbreviation List 2023
Plan Z - Nazi Shipbuilding Plans
Walgreens San Pedro And Hildebrand
Mission Impossible 7 Showtimes Near Marcus Parkwood Cinema
Inter-Tech IM-2 Expander/SAMA IM01 Pro
Tinker Repo
I Saysopensesame
Busted Newspaper Fauquier County Va
Yog-Sothoth
Scheuren maar: Ford Sierra Cosworth naar de veiling
Violent Night Showtimes Near Amc Dine-In Menlo Park 12
Mals Crazy Crab
Inter Miami Vs Fc Dallas Total Sportek
What we lost when Craigslist shut down its personals section
Gt7 Roadster Shop Rampage Engine Swap
10 Best Quotes From Venom (2018)
Autotrader Bmw X5
UPS Drop Off Location Finder
Giantess Feet Deviantart
Selfservice Bright Lending
Xemu Vs Cxbx
Sephora Planet Hollywood
Boggle BrainBusters: Find 7 States | BOOMER Magazine
Craigs List Jonesboro Ar
Ludvigsen Mortuary Fremont Nebraska
Craigslist Ludington Michigan
Saybyebugs At Walmart
Questions answered? Ducks say so in rivalry rout
Owa Hilton Email
Avatar: The Way Of Water Showtimes Near Jasper 8 Theatres
Oak Hill, Blue Owl Lead Record Finastra Private Credit Loan
Pilot Travel Center Portersville Photos
Craigslist Charlestown Indiana
The Ultimate Guide To 5 Movierulz. Com: Exploring The World Of Online Movies
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 6862

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.