Skip to content

Latest commit

 

History

History
103 lines (75 loc) · 11.8 KB

File metadata and controls

103 lines (75 loc) · 11.8 KB
title Windows Forms Application Basics (Visual Basic)
ms.date 07/20/2015
ms.prod .net
ms.suite
ms.technology
devlang-visual-basic
ms.topic article
helpviewer_keywords
Windows applications
Windows Forms, Visual Basic
ms.assetid 0b919d30-7fd6-42db-85c8-543d15312441
caps.latest.revision 20
author dotnet-bot
ms.author dotnetcontent

Windows Forms Application Basics (Visual Basic)

An important part of [!INCLUDEvbprvb] is the ability to create Windows Forms applications that run locally on users' computers. You can use Visual Studio to create the application and user interface using Windows Forms. A Windows Forms application is built on classes from the xref:System.Windows.Forms namespace.

Designing Windows Forms Applications

You can create Windows Forms and Windows service applications with [!INCLUDEvsprvs]. For more information, see the following topics:

Building Rich, Interactive User Interfaces

Windows Forms is the smart-client component of the [!INCLUDEdnprdnshort], a set of managed libraries that enable common application tasks such as reading and writing to the file system. Using a development environment like [!INCLUDEvsprvs], you can create Windows Forms applications that display information, request input from users, and communicate with remote computers over a network.

In Windows Forms, a form is a visual surface on which you display information to the user. You commonly build Windows Forms applications by placing controls on forms and developing responses to user actions, such as mouse clicks or key presses. A control is a discrete user interface (UI) element that displays data or accepts data input.

Events

When a user does something to your form or one of its controls, it generates an event. Your application reacts to these events by using code, and processes the events when they occur. For more information, see Creating Event Handlers in Windows Forms.

Controls

Windows Forms contains a variety of controls that you can place on forms: controls that display text boxes, buttons, drop-down boxes, radio buttons, and even Web pages. For a list of all the controls you can use on a form, see Controls to Use on Windows Forms. If an existing control does not meet your needs, Windows Forms also supports creating your own custom controls using the xref:System.Windows.Forms.UserControl class.

Windows Forms has rich UI controls that emulate features in high-end applications like Microsoft Office. Using the xref:System.Windows.Forms.ToolStrip and xref:System.Windows.Forms.MenuStrip control, you can create toolbars and menus that contain text and images, display submenus, and host other controls such as text boxes and combo boxes.

With the [!INCLUDEvsprvs] drag-and-drop forms designer, you can easily create Windows Forms applications: just select the controls with your cursor and place them where you want on the form. The designer provides tools such as grid lines and "snap lines" to take the hassle out of aligning controls. And whether you use [!INCLUDEvsprvs] or compile at the command line, you can use the xref:System.Windows.Forms.FlowLayoutPanel, xref:System.Windows.Forms.TableLayoutPanel and xref:System.Windows.Forms.SplitContainer controls to create advanced form layouts with minimal time and effort.

Custom UI Elements

Finally, if you must create your own custom UI elements, the xref:System.Drawing namespace contains all of the classes you need to render lines, circles, and other shapes directly on a form.

For step-by-step information about using these features, see the following Help topics.

To See
Create a new Windows Forms application with [!INCLUDEvsprvs] Walkthrough: Creating a Simple Windows Form
Use controls on forms How to: Add Controls to Windows Forms
Create graphics with xref:System.Drawing Getting Started with Graphics Programming
Create custom controls How to: Inherit from the UserControl Class

Displaying and Manipulating Data

Many applications must display data from a database, XML file, XML Web service, or other data source. Windows Forms provides a flexible control called the xref:System.Windows.Forms.DataGridView control for rendering such tabular data in a traditional row and column format, so that every piece of data occupies its own cell. Using xref:System.Windows.Forms.DataGridView you can customize the appearance of individual cells, lock arbitrary rows and columns in place, and display complex controls inside cells, among other features.

Connecting to data sources over a network is a simple task with Windows Forms smart clients. The xref:System.Windows.Forms.BindingSource component, new with Windows Forms in [!INCLUDEvsprvslong] and the [!INCLUDEdnprdnlong], represents a connection to a data source, and exposes methods for binding data to controls, navigating to the previous and next records, editing records, and saving changes back to the original source. The xref:System.Windows.Forms.BindingNavigator control provides a simple interface over the xref:System.Windows.Forms.BindingSource component for users to navigate between records.

Data-Bound Controls

You can create data-bound controls easily using the Data Sources window, which displays data sources such as databases, Web services, and objects in your project. You can create data-bound controls by dragging items from this window onto forms in your project. You can also data-bind existing controls to data by dragging objects from the Data Sources window onto existing controls.

Settings

Another type of data binding you can manage in Windows Forms is settings. Most smart-client applications must retain some information about their run-time state, such as the last-known size of forms, and retain user-preference data, such as default locations for saved files. The application-settings feature addresses these requirements by providing an easy way to store both types of settings on the client computer. Once defined using either [!INCLUDEvsprvs] or a code editor, these settings are persisted as XML and automatically read back into memory at run time.

For step-by-step information about using these features, see the following Help topics.

To See
Use the xref:System.Windows.Forms.BindingSource component How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer
Work with [!INCLUDEvstecado] data sources How to: Sort and Filter ADO.NET Data with the Windows Forms BindingSource Component
Use the Data Sources window Walkthrough: Displaying Data on a Windows Form

Deploying Applications to Client Computers

Once you have written your application, you must send it to your users so that they can install and run it on their own client computers. Using the [!INCLUDEndptecclick] technology, you can deploy your applications from within [!INCLUDEvsprvs] by using just a few clicks and provide users with a URL pointing to your application on the Web. [!INCLUDEndptecclick] manages all of the elements and dependencies in your application and ensures that the application is properly installed on the client computer.

[!INCLUDEndptecclick] applications can be configured to run only when the user is connected to the network, or to run both online and offline. When you specify that an application should support offline operation, [!INCLUDEndptecclick] adds a link to your application in the user's Start menu, so that the user can open it without using the URL.

When you update your application, you publish a new deployment manifest and a new copy of your application to your Web server. [!INCLUDEndptecclick] detects that there is an update available and upgrades the user's installation; no custom programming is required to update old assemblies.

For a full introduction to [!INCLUDEndptecclick], see ClickOnce Security and Deployment. For step-by-step information about using these features, see the following Help topics:

To See
Deploy an application with [!INCLUDEndptecclick] How to: Publish a ClickOnce Application using the Publish Wizard

Walkthrough: Manually Deploying a ClickOnce Application
Update a [!INCLUDEndptecclick] deployment How to: Manage Updates for a ClickOnce Application
Manage security with [!INCLUDEndptecclick] How to: Enable ClickOnce Security Settings

Other Controls and Features

There are many other features in Windows Forms that make implementing common tasks fast and easy, such as support for creating dialog boxes, printing, adding Help and documentation, and localizing your application to multiple languages. In addition, Windows Forms relies on the robust security system of the [!INCLUDEdnprdnshort], enabling you to release more secure applications to your customers.

For step-by-step information about using these features, see the following Help topics:

To See
Print the contents of a form How to: Print Graphics in Windows Forms

How to: Print a Multi-Page Text File in Windows Forms
Learn more about Windows Forms security Security in Windows Forms Overview

See Also

xref:Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
Windows Forms Overview
My.Forms Object