This documentation is archived and is not being maintained.

Code for Windows Forms Applications

Visual Studio .NET 2003

This topic is designed to help you find code that demonstrates how to perform common programming tasks in Windows Forms applications. The following categories are represented in the list below:

You can also find sample code for Windows Forms applications in these locations:

Application Creation

Example of...

Creating a simple hello world application

Creating a simple distributed application that calls an XML Web service

Calling an XML Web service

Serializing objects

Form Manipulation

Example of...

Making a form invisible

Making a form transparent

Keeping a form on top of the screen

Displaying a form as a modal dialog box

Setting a form's border style

Manipulate a form's size programmatically

Setting a form's location

Displaying localized string from a resource file

Event Handling

Example of...

Creating basic event handlers on the designer

Creating default event handlers

Creating event handlers at run time

Handling multiple events with the same event handler

Determining which modifier key was pressed


Example of...

Inheriting a Windows form

Creating a simple application using visual inheritance

Dialog Boxes

Example of...

Displaying a dialog box

Displaying a message box

Closing dialog boxes and retaining input

Retrieving results from dialog boxes

Retrieving dialog box information selectively

Retrieving information from a dialog box's parent form

Creating a simple application that retrieves dialog box information

Data Access

Example of...

Navigating data on a Windows form

Creating a simple data access form

Using parameterized queries

Creating a simple master-detail form

MDI Forms

Example of...

Creating MDI child forms

Determining the active MDI child form

Sending data to an MDI child form

Arranging the layout of MDI child forms

Keeping track of the forms an MDI application has open

Creating an Outlook-like user interface

Menu Manipulation

Example of...

Adding menus to a form

Creating context menus

Rearranging menu items

Copying items from one menu to another

Enabling and disabling menu items

Removing items from menus

Merging menu items programmatically

Adding check marks and shortcut keys to menus

Creating a simple application using context menus

Graphics and GDI+

Example of...

Creating graphical objects on Windows Forms

Working with pens, brushes, and colors

Drawing lines and shapes

Rendering text with GDI+

Rendering images with GDI+


Example of...

Creating a standard print job

Allowing the user to specify print options

Choosing a printer

Printing graphics

Printing text

Displaying a message that a print job has finished

Allowing print preview

Drag and Drop

Example of...

Dragging and dropping data

Placing data on the clipboard

Retrieving data from the clipboard

Related Code Examples

Code for Windows Forms Controls

Code Examples for Visual Basic Programmers