mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-09 23:43:28 +02:00
Initial publish of WinForms for .NET 5. (#96)
* Migrate inprogress winforms contnet from docs * Fix preview note * Fix vb code * Minor fixes to keyboard articles * Minor adjustment to overview * Test redirects for 4.0 -> 5.0 * adjust links * Add mouse input section winforms (#81) * Update projects to .NET 5 * Update keyboard desc * Finish mouse events * Add remaining mouse articles;code * finish mouse input * minor fixes * Remove branch restriction (#82) * Update build-validation.yml (#84) * Update build-validation.yml (#85) * Fix vb proj * Add WinForms tutorial (#91) * redirect between overview * New create an app tutorial * Fix markdown * Fix preserve view setting * Add forms articles (#93) * Add forms articles * Fix warnings * Winforms publish (#95) * Prep TOC for publish * Updated date * Automatic how-to topic type * Update desc/headers * Fix links * Fix build errors * Add preview note * Update toc landing page * Convert old style project files * update download links * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]> * Adjust number key * Update dotnet-desktop-guide/net/winforms/overview/index.md * Try toc position task via bookmark * Improve images * Remove sentence * File redirects Co-authored-by: Genevieve Warren <[email protected]>
This commit is contained in:
co-authored by
Genevieve Warren
parent
f7e5ce92ea
commit
184e6c9a0c
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: Add Controls to a Form
|
||||
description: Learn how to add a control a form in Windows Forms for .NET
|
||||
ms.date: 10/26/2020
|
||||
dev_langs:
|
||||
- "csharp"
|
||||
- "vb"
|
||||
helpviewer_keywords:
|
||||
- "Windows Forms controls, adding to form"
|
||||
- "controls [Windows Forms], adding"
|
||||
---
|
||||
|
||||
# Add a control (Windows Forms .NET)
|
||||
|
||||
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.<!-- TODO For more information about controls, see [Forms overview](..\forms\overview.md). -->
|
||||
|
||||
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.
|
||||
|
||||
[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)]
|
||||
|
||||
## 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.
|
||||
|
||||
:::image type="content" source="media/how-to-add-to-a-form/toolbox-double-click.gif" alt-text="Double-click a control in the toolbox on visual studio for .NET Windows Forms":::
|
||||
|
||||
### 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.
|
||||
|
||||
:::image type="content" source="media/how-to-add-to-a-form/toolbox-drag-draw.gif" alt-text="Drag-select and draw a control from the toolbox on visual studio for .NET Windows Forms":::
|
||||
|
||||
## Add with code
|
||||
|
||||
Controls can be created and then added to a form at run time with the form's <xref:System.Windows.Forms.Control.Controls%2A> collection. This collection can also be used to remove controls from a form.
|
||||
|
||||
The following code adds and positions two controls, a [Label](xref:System.Windows.Forms.Label) and a [TextBox](xref:System.Windows.Forms.TextBox):
|
||||
|
||||
:::code language="csharp" source="snippets/how-to-add-to-a-form/cs/Form1.cs" id="CreateControl":::
|
||||
|
||||
:::code language="vb" source="snippets/how-to-add-to-a-form/vb/Form1.vb" id="CreateControl":::
|
||||
|
||||
## See also
|
||||
|
||||
- [How to: Set the Text Displayed by a Windows Forms Control](how-to-set-the-display-text.md)
|
||||
- [How to: Add an access key shortcut to a control](how-to-create-access-keys.md)
|
||||
- <xref:System.Windows.Forms.Label>
|
||||
- <xref:System.Windows.Forms.TextBox>
|
||||
- <xref:System.Windows.Forms.Button>
|
||||
Reference in New Issue
Block a user