Code in trong windows form
Chuyển đến nội dung chính Trình duyệt này không còn được hỗ trợ nữa. Show
Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật. Add a control to a form (Windows Forms .NET)
Trong bài viết nàyMost 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 6 and .NET 5 (including .NET Core 3.1) is under construction. Add with DesignerVisual 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-clickingWhen a control is double-clicked, it is automatically added to the current open form with default settings.
Add the control by drawingSelect 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 with codeControls 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:
See also
Phản hồiGửi và xem ý kiến phản hồi dành cho Tài nguyên bổ sungTài nguyên bổ sungTrong bài viết nàySkip to main content This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Create a Windows Forms app in Visual Studio with C#
In this articleApplies to: Visual Studio Visual Studio for Mac Visual Studio CodeIn this short introduction to the Visual Studio integrated development environment (IDE), you'll create a simple C# application that has a Windows-based user interface (UI). Create a projectFirst, you'll create a C# application project. The project type comes with all the template files you'll need, before you've even added anything.
Create the applicationAfter you select your C# project template and name your file, Visual Studio opens a form for you. A form is a Windows user interface. We'll create a "Hello World" application by adding controls to the form, and then we'll run the app. Add a button to the form
Add a label to the formNow that we've added a button control to create an action, let's add a label control to send text to.
Add code to the form
Run the application
Create the applicationAfter you select your C# project template and name your file, Visual Studio opens a form for you. A form is a Windows user interface. We'll create a "Hello World" application by adding controls to the form, and then we'll run the app. Add a button to the form
Add a label to the formNow that we've added a button control to create an action, let's add a label control to send text to.
Add code to the form
Run the application
Next stepsTo learn more, continue with the following tutorial: See also
FeedbackSubmit and view feedback for Additional resourcesAdditional resourcesIn this article |