Namespace System.Windows.Forms
Provides classes and interfaces that enable you to create Windows-based applications that take full advantage of the rich user interface features available in the Microsoft .NET Framework.
Classes
Button
Represents a Windows control that allows the user to initiate an action, such as submitting a form or dialog box.
TextBox
Represents a Windows control that displays text, allows a user to enter or edit text, and displays both text and graphics.
Label
Represents a Windows control that displays a label for another control in a form.
Form
Represents a window, which is a separate user interface object that the user can create, open, minimize, maximize, close, and interact with.
DataGridView
Represents a Windows Forms control that displays data in a tabular format.
Interfaces
IDataGridColumnStyle
Defines the functionality for a column in a data-bound control.
Structures
Point
Represents an ordered pair of integers that defines a point in two-dimensional space.
Size
Represents a location in three-dimensional space with x, y, and z coordinates.
Class Button
Represents a Windows control that allows the user to initiate an action, such as submitting a form or dialog box.
Public Constructors
Initializes a new instance of the Button
class.
Public Properties
Text: string
Gets or sets the text displayed on the control.
Enabled: bool
Gets or sets a value indicating whether the control can respond to user interaction.
Size: Size
Gets or sets the height and width of the control.
Public Methods
Simulates a click on the control.
Events
Click: EventHandler
Occurs when the control is clicked.
Class TextBox
Represents a Windows control that displays text, allows a user to enter or edit text, and displays both text and graphics.
Public Properties
Text: string
Gets or sets the current text in the text box.
Multiline: bool
Gets or sets a value indicating whether the text box control is a multiline text box.
Public Methods
Appends the specified text to the current text of the text box.
text
: The string to append to the text box.
Class Label
Represents a Windows control that displays a label for another control in a form.
Public Properties
Text: string
Gets or sets the text displayed on the control.
Class Form
Represents a window, which is a separate user interface object that the user can create, open, minimize, maximize, close, and interact with.
Public Properties
Text: string
Gets or sets the title bar text of the form.
Controls: ControlCollection
Gets a collection of the controls contained within the form.
Public Methods
Shows a form as a modal dialog box.
Events
Load: EventHandler
Occurs when the form is loaded.
Class DataGridView
Represents a Windows Forms control that displays data in a tabular format.
Public Properties
DataSource: object
Gets or sets the data source for the control.
Columns: DataGridViewColumnCollection
Gets the collection of columns in the control.
Example Usage (C#)
using System;
using System.Windows.Forms;
public class MainForm : Form
{
private Button myButton;
private TextBox myTextBox;
private Label myLabel;
public MainForm()
{
this.Text = "WinForms Example";
this.Size = new System.Drawing.Size(400, 300);
myLabel = new Label();
myLabel.Text = "Enter your name:";
myLabel.Location = new System.Drawing.Point(20, 20);
myLabel.AutoSize = true;
myTextBox = new TextBox();
myTextBox.Location = new System.Drawing.Point(150, 20);
myTextBox.Size = new System.Drawing.Size(200, 20);
myButton = new Button();
myButton.Text = "Greet Me";
myButton.Location = new System.Drawing.Point(150, 60);
myButton.Click += new EventHandler(MyButton_Click);
this.Controls.Add(myLabel);
this.Controls.Add(myTextBox);
this.Controls.Add(myButton);
}
private void MyButton_Click(object sender, EventArgs e)
{
MessageBox.Show($"Hello, {myTextBox.Text}!");
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}