Windows Applications (How Do I in C#)
This page links to Help on widely used Windows applications tasks. For more information about other categories of popular tasks covered in Help, see How Do I in C#.
General
Overview of Windows-based Applications
Provides an overview of Windows applications that you can create by using Visual Studio.Choosing Between Windows Forms and Web Forms
Discuss the features and characteristics of each technology to help you determine which is best suited to your application.
Working with Forms
Windows Forms Designer
How to: Choose the Startup Form in a Windows Application
Provides information about how to set the startup form in a Windows application.How to: Connect Multiple Events to a Single Event Handler in Windows Forms
Explains how to connect multiple events to a single event handler in Windows Forms application by using the Events view of the Properties window in C#.How to: Create a Multipane User Interface with Windows Forms
Explains how to create a multipane user interface that is similar to the one used in Microsoft Outlook, with a Folder list, a Messages pane, and a Preview pane.How to: Add Background Images to Windows Forms
Explains how to place a background image in a control or on the form itself. You can accomplish this easily by using the Properties window.How to: Set ToolTips for Controls on a Windows Form at Design Time
Explains how you can set a tooltip string in code or in the Windows Forms Designer.How to: Add ActiveX Controls to Windows Forms
Explains how you can put ActiveX controls on Windows Forms.How to: Create Access Keys for Windows Forms Controls
Explains how to create an access key in the text of a menu, menu item, or the label of a control such as a button.
Working with Windows Forms at Run Time
How to: Add to or Remove from a Collection of Controls at Run Time
Provides common tasks in application development such as adding and removing controls from any container control on your forms.How to: Enable Windows XP Visual Styles
Shows how to enable visual styles in the client area of a Windows Form.How to: Make a Startup Windows Form Invisible
Shows how to make the main form of a Windows-based application invisible when the application starts.How to: Keep a Windows Form on Top
Shows how to make a form the top-most form in a Windows Forms application at design time or programmatically.How to: Display Modal and Modeless Windows Forms
Shows how to display a form as a modal or modeless dialog box.
Controls
TextBox Controls
How to: Select Text in the Windows Forms TextBox Control
Shows you how to select text programmatically in the Windows Forms TextBox control.How to: Put Quotation Marks in a String (Windows Forms)
Shows you how to place quotation marks (" ") in a string of text.How to: Create a Read-Only Text Box (Windows Forms)
Shows you how to transform an editable Windows Forms text box into a read-only control.How to: Create a Password Text Box with the Windows Forms TextBox Control
Shows you how to create a password text box with the Windows Forms TextBox control.How to: Control the Insertion Point in a Windows Forms TextBox Control
Shows you how to control the insertion point in a TextBox control.How to: Bind Data to the MaskedTextBox Control
Shows you how to bind data to a MaskedTextBox control.Walkthrough: Working with the MaskedTextBox Control
Illustrates how to perform the following tasks:Initializing the MaskedTextBox control.
Alerting the user when a character does not conform to the mask.
Alerting users when the value they are trying to commit is invalid for the type.
RichTextBox Controls
How to: Load Files into the Windows Forms RichTextBox Control
Explains how to load files into a Windows Forms RichTextBox control that can display a plain-text, Unicode plain-text, or Rich-Text-Format (RTF) file.How to: Display Scroll Bars in the Windows Forms RichTextBox Control
Provides seven possible values for the ScrollBars property of the RichTextBox control, which are described in the table below.How to: Set Font Attributes for the Windows Forms RichTextBox Control
Describes how you can make the selected characters bold, underlined, or italic, by using the SelectionFont property.How to: Set Indents, Hanging Indents, and Bulleted Paragraphs with the Windows Forms RichTextBox Control
Describes how you can format selected paragraphs as bulleted lists by setting the SelectionBullet property. You can also use the SelectionIndent, SelectionRightIndent, and SelectionHangingIndent properties to set the indentation of paragraphs relative to the left and right edges of the control, and the left edge of other lines of text.How to: Enable Drag-and-Drop Operations with the Windows Forms RichTextBox Control
Describes how to enable drag-and-drop operations with the Windows Forms RichTextBox control by handling the DragEnter and DragDrop events.How to: Display Web-Style Links with the Windows Forms RichTextBox Control
Describes how you can write code that opens a browser window by showing the Web site specified in the link text when the link is clicked.
Button Controls
How to: Respond to Windows Forms Button Clicks
Explains the most basic use of a Windows Forms Button control that is executing some code when the button is clicked.How to: Designate a Windows Forms Button as the Accept Button Using the Designer
Explains how you can designate a Button control to be the accept button, also known as the default button. Whenever the user presses ENTER, the default button is clicked regardless of which other control on the form has the focus.How to: Designate a Windows Forms Button as the Cancel Button Using the Designer
Explains how you can designate a Button control to be the cancel button. A cancel button is clicked whenever the user presses ESC, regardless of which other control on the form has the focus. Such a button is usually programmed to let the user quickly exit an operation without committing to any action.
CheckBox Controls
How to: Set Options with Windows Forms CheckBox Controls
Provides information on how a Windows Forms CheckBox control is used to give users True/False or Yes/No options. The control displays a check mark when it is selected.How to: Respond to Windows Forms CheckBox Clicks
Explains how you can program your application to perform some action depending upon the state of the check box.
RadioButton Control
- How to: Group Windows Forms RadioButton Controls to Function as a Set
Explains how you group radio buttons by drawing them inside a container such as a Panel control, a GroupBox control, or a form.
ListBox, ComboBox and CheckedListBox Controls
How to: Bind a Windows Forms ComboBox or ListBox Control to Data
Explains how you can bind the ComboBox and ListBox to data to perform tasks such as browsing data in a database, entering new data, or editing existing data.How to: Create a Lookup Table for a Windows Forms ComboBox, ListBox, or CheckedListBox Control
Provides tables that show an example of how to store and display order-form data for food.How to: Add and Remove Items from a Windows Forms ComboBox, ListBox, or CheckedListBox Control
Provides an example on how to add items to a Windows Forms ComboBox, ListBox, or CheckedListBox. However, this topic demonstrates the simplest method and requires no data binding.How to: Access Specific Items in a Windows Forms ComboBox, ListBox, or CheckedListBox Control
Demonstrates accessing specific items in a Windows Forms ComboBox, ListBox, or CheckedListBox. It lets you to programmatically determine what is in a list, at any given position.How to: Sort the Contents of a Windows Forms ComboBox, ListBox, or CheckedListBox Control
Demonstrates how to use data sources that support sorting: data views, data view managers, and sorted arrays.
CheckedListBox Control
- How to: Determine Checked Items in the Windows Forms CheckedListBox Control
Demonstrates how to determine checked items in the Windows Forms CheckedListBox control by either iterating through the collection stored in the CheckedItems property, or step through the list using the GetItemChecked method to determine which items are checked.
DataGridView Controls
How to: Bind Data to the Windows Forms DataGridView Control Using the Designer
Explains how you can use the designer to connect the DataGridView control to data sources of several different varieties, including databases, business objects, or Web services.How to: Validate Data in the Windows Forms DataGridView Control
Demonstrates how to validate data entered by a user into a DataGridView control.How to: Handle Errors That Occur During Data Entry in the Windows Forms DataGridView Control
Demonstrates how to use the DataGridView control to report data entry errors to the user.How to: Specify Default Values for New Rows in the Windows Forms DataGridView Control
Demonstrates how to specify default values for new rows using the DefaultValuesNeeded event.How to: Create an Unbound Windows Forms DataGridView Control
Demonstrates how to populate a DataGridView control programmatically without binding it to a data source.How to: Add an Unbound Column to a Data-Bound Windows Forms DataGridView Control
Demonstrates how to create an unbound column of Details buttons to display a child table related to a particular row in a parent table when you implement a master/detail scenario.How to: Display Images in Cells of the Windows Forms DataGridView Control
Demonstrates how to extract an icon from an embedded resource and convert it to a bitmap for display in every cell of an image column.How to: Host Controls in Windows Forms DataGridView Cells
Shows how to create a calendar column. The cells of this column display dates in ordinary text box cells, but when the user edits a cell, a DateTimePicker control appears.Walkthrough: Validating Data in the Windows Forms DataGridView Control
Demonstrates how you retrieve rows from the Customers table in the Northwind sample database and display them in a DataGridView control. When you edit a cell in the CompanyName column and try to leave it, the new company name string is checked to make sure it is not empty. If the new value is an empty string, the DataGridView prevents the cursor from leaving the cell until a non-empty string is entered.Walkthrough: Handling Errors that Occur During Data Entry in the Windows Forms DataGridView Control
Demonstrates how you retrieve rows from the Customers table in the Northwind sample database and display them in a DataGridView control. When a duplicate CustomerID value is detected in a new row or an edited existing row, the DataError event happens, which is handled by showing a MessageBox that displays the exception.Walkthrough: Creating an Unbound Windows Forms DataGridView Control
Shows how to populate a DataGridView control and manage the addition and deletion of rows in "unbound" mode.
DataGridView Layout and Formatting
How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer
Demonstrates a procedure to make the columns that contain the data read-only.How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer
Demonstrates enabling your users to reorder the columns. When you enable column reordering, users can move a column to a new position by dragging the column header with the mouse.How to: Change the Order of Columns in the Windows Forms DataGridView Control Using the Designer
Explains how to change the order of columns in the Windows Forms DataGridView control using the Designer.How to: Add and Remove Columns in the Windows Forms DataGridView Control Using the Designer
Explains how to add or remove columns in the Windows Forms DataGridView control using the Designer.
Data Binding with Controls
- How to: Handle Errors and Exceptions that Occur with Databinding
Demonstrates how to handle errors and exceptions that occur during a data-binding operation.
BindingSource Controls
How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer
Demonstrates how to bind a control at design time.How to: Create a Lookup Table with the Windows Forms BindingSource Component
Demonstrates how to use a ComboBox control to display the field with the foreign-key relationship from the parent to the child table.How to: Reflect Data Source Updates in a Windows Forms Control with the BindingSource
Demonstrates using the ResetBindings method to notify a bound control about an update in the data source.How to: Sort and Filter ADO.NET Data with the Windows Forms BindingSource Component
Demonstrates how to sort and filter data with the BindingSource.How to: Bind to a Web Service Using the Windows Forms BindingSource
Demonstrates how to create and bind to a client-side proxy.
Binding Navigator
How to: Navigate Data with the Windows Forms BindingNavigator Control
Explains how to set up the BindingNavigator control.How to: Move Through a DataSet with the Windows Forms BindingNavigator Control
Demonstrates how to use a BindingNavigator control to move through the results of a database query.
ListView
How to: Add and Remove Items with the Windows Forms ListView Control
Explains the process of adding and removing an item to a Windows Forms ListView control. Adding or removing list items can be done at any time.How to: Add Search Capabilities to a ListView Control
Demonstrates creating professional-looking Windows Forms applications in a short of amount of time.How to: Select an Item in the Windows Forms ListView Control
Demonstrates how to programmatically select an item in a Windows Forms ListView control.How to: Display Icons for the Windows Forms ListView Control
Demonstrates how to display images in a list view.How to: Display Subitems in Columns with the Windows Forms ListView Control
Demonstrates how to add subitems to a list item.
TreeView
How to: Set Icons for the Windows Forms TreeView Control
Demonstrates how to display images in a tree view.How to: Add and Remove Nodes with the Windows Forms TreeView Control
Demonstrates how to add and remove nodes programmatically to and from a tree view.How to: Determine Which TreeView Node Was Clicked (Windows Forms)
Demonstrates how to determine which TreeView node was clicked.
Container Controls
How to: Split a Window Horizontally
Explains how to make the splitter that divides the SplitContainer control horizontally.How to: Create a Multipane User Interface with Windows Forms
Demonstrates how you create a multipane user interface that is similar to the one used in Microsoft Outlook, with a Folder list, a Messages pane, and a Preview pane.How to: Span Rows and Columns in a TableLayoutPanel Control
Demonstrates how controls in a TableLayoutPanel control can span adjacent rows and columns.Walkthrough: Arranging Controls on Windows Forms Using a TableLayoutPanel
Illustrates how to perform the following tasks:Creating a Windows Forms project.
Arranging Controls in Rows and Columns.
Setting Row and Column Properties.
Spanning Rows and Columns with a Control.
Automatic Handling of Overflows.
Inserting Controls by double-clicking them in the Toolbox.
Inserting a Control by Drawing Its Outline.
Reassigning Existing Controls to a Different Parent.
Walkthrough: Arranging Controls on Windows Forms Using a FlowLayoutPanel
Illustrates how to perform the following tasks:Creating a Windows Forms project.
Arranging Controls Horizontally and Vertically.
Changing Flow Direction.
Inserting Flow Breaks.
Arranging Controls Using Padding and Margins.
Inserting Controls by double-clicking them in the Toolbox.
Inserting a Control by Drawing its Outline.
Inserting Controls Using the Caret.
Reassigning Existing Controls to a Different Parent.
Picture and Image Controls
How to: Load a Picture Using the Designer (Windows Forms)
Explains how you can load and display a picture on a form at design time by setting the Image property to a valid picture.How to: Set Pictures at Run Time (Windows Forms)
Explains how you can programmatically set the image displayed by a Windows Forms PictureBox control.How to: Modify the Size or Placement of a Picture at Run Time (Windows Forms)
Explains how you can set the SizeMode property of a Windows Forms PictureBox control on a form to different values.
DateTimePicker
How to: Set and Return Dates with the Windows Forms DateTimePicker Control
Explains how you can set the Value property before the control is displayed to determine which date will be initially selected in the control.How to: Display a Date in a Custom Format with the Windows Forms DateTimePicker Control
Explains how to display a custom format and set the CustomFormat property to a format string.
MonthCalendar
How to: Select a Range of Dates in the Windows Forms MonthCalendar Control
Demonstrates how you can set a range of dates or get a selection range set by the user with properties of the MonthCalendar control.How to: Display Specific Days in Bold with the Windows Forms MonthCalendar Control
Demonstrates how you make a date appear in bold type or in the regular font.How to: Display More than One Month in the Windows Forms MonthCalendar Control
Demonstrates how you display multiple months in a Windows Forms MonthCalendar control.How to: Change the Windows Forms MonthCalendar Control's Appearance
Demonstrates how to change the month calendar's color scheme, to display the current date at the bottom of the control and to display week numbers.
Data Access (for Windows Forms)
Walkthrough: Passing Data Between Forms in a Windows Application
Provides step by step instructions for passing data from one form into a method on a second form.Walkthrough: Displaying Data on a Form in a Windows Application
Creates a simple form that displays data from a single table in several individual controls.Walkthrough: Creating a Form to Search Data in a Windows Application
Demonstrates creating a Windows Form to search data.
ToolStrip
How to: Position a ToolStripItem on a ToolStrip
Explains how you can move or add a ToolStripItem to the left or right side of a ToolStrip.How to: Disable ToolStripMenuItems Using the Designer
Explains how you can disable a menu item at design time.How to: Move ToolStripMenuItems
Explains how you can move the entire top-level menus and their menu items to a different place on the MenuStrip. You can also move individual menu items between top-level menus or change the position of menu items within a menu.How to: Change the Appearance of ToolStrip Text and Images in Windows Forms
Explains how you can control whether text and images are displayed on a ToolStripItem and how they are aligned relative to each other and the ToolStrip.
Context Menus
How to: Associate a Shortcut Menu with a Windows Forms NotifyIcon Component
Demonstrates how to associate a shortcut menu with a Windows Forms NotifyIcon component.How to: Add and Remove Menu Items with the Windows Forms ContextMenu Component
Explains how to add and remove shortcut menu items in Windows Forms.
Printing
How to: Create Standard Windows Forms Print Jobs
Shows you how to specify what to print and how to print it by writing code to handle the PrintPage event.How to: Complete Windows Forms Print Jobs
Shows you how to complete a print job by handling the EndPrint event of the PrintDocument component.How to: Print a Multi-Page Text File in Windows Forms
Shows you how to print text in a Windows Form by using methods for drawing objects (graphics or text) to a device, such as a screen or printer.How to: Choose the Printers Attached to a User's Computer in Windows Forms
Shows you how to choose a printer and then print a file.How to: Capture User Input from a PrintDialog at Run Time
Shows you how change print options at run time. This is done through the PrintDialog component and the PrinterSettings class.
User Controls and Custom Controls
Adding Controls to Your User Control
Demonstrates adding controls to your User Control.Adding Code to Your User Control
Demonstrates adding code to your User Control.
Multiple Document Interfaces (MDI)
How to: Create MDI Parent Forms
Demonstrates how to create an MDI parent form at design time.How to: Create MDI Child Forms
Demonstrates how to create MDI child forms that display a RichTextBox control, similar to most word-processing applications.How to: Arrange MDI Child Forms
Demonstrates how to display the child forms as cascading, as horizontally or vertically tiled, or as child form icons arranged along the lower portion of the multiple-document interface (MDI) form.How to: Determine the Active MDI Child
Demonstrates how to determine the active MDI child and copy its text to the Clipboard.How to: Send Data to the Active MDI Child
Demonstrates how to send data to the active MDI child window from the Clipboard.
Graphics
How to: Draw an Outlined Shape
Shows how to draw outlined ellipses and rectangles on a form.How to: Create a Linear Gradient
Shows how to fill a line, an ellipse, and a rectangle with a horizontal linear gradient brush.How to: Create a Path Gradient
Shows you how to customize the way you fill a shape with gradually changing colors.How to: Create Figures from Lines, Curves, and Shapes
Explains how to create a path that has a single or multiple figures.How to: Create Graphics Objects for Drawing
Explains how to create graphics objects for drawing.How to: Create Thumbnail Images
Demonstrates how to construct an image object from a bitmap file.How to: Create Vertical Text
Demonstrates how to use a StringFormat object to specify that text be drawn vertically rather than horizontally.How to: Align Drawn Text
Demonstrates how to draw text in a rectangle. Each line of text is centered, and the entire block of text is centered in the rectangle.How to: Draw a Line on a Windows Form
Demonstrates how to draw a line on a form.How to: Rotate, Reflect, and Skew Images
Demonstrates how to rotate, reflect, and skew an image by specifying destination points for the upper-left, upper-right, and lower-left corners of the original image.How to: Draw Text on a Windows Form
Shows how to use the DrawString method of the Graphics to draw text on a form.How to: Load and Display Bitmaps
Shows how to load a bitmap from a file and display that bitmap on the screen.How to: Load and Display Metafiles
Shows how to use the methods of the Metafile class for recording, displaying, and examining vector images.
Localizing and Globalizing Windows Forms
Walkthrough: Localizing Windows Forms
Demonstrates processes of localizing a Windows Application project.How to: Support Localization on Windows Forms Using AutoSize and the TableLayoutPanel Control
Demonstrates enabling a layout that adapts to varying string sizes.How to: Set the Culture and UI Culture for Windows Forms Globalization
Demonstrates how to set formatting options appropriate for a specific culture.How to: Display Right-to-Left Text in Windows Forms for Globalization
Demonstrates how to display right-to-left text.
Additional Resources
Visual Studio 2005 Developer Center
Contains many articles and resources on developing applications using Visual Studio. This site is updated regularly with new content.Visual C# Developer Center
Contains many articles and resources on developing C# applications. This site is updated regularly with new content.Microsoft .NET Framework Developer Center
Contains many articles and resources on developing and debugging .NET Framework applications. This site is updated regularly with new content.