Click to Rate and Give Feedback
Related Articles
Here the author introduces SQL Server Data Services, which exposes its functionality over standard Web service interfaces.

By David Robinson (July 2008)
Here the author answers questions regarding the Entity Framework and provides an understanding of how and why it was developed.

By Elisa Flasko (July 2008)
Here we present techniques for programmatic and declarative data binding and display with Windows Presentation Foundation.

By Josh Smith (July 2008)
Systems that handle failure without losing data are elusive. Learn how to achieve systems that are both scalable and robust.

By Udi Dahan (July 2008)
More ...
Articles by this Author
The Windows Presentation Foundation provides new techniques for UI-based developing applications and makes better use of current hardware and technologies. In this article, Ian Griffiths and Chris Sells explain 10 of the most significant advances that make WPF superior to its Win32 predecessors.

By Ian Griffiths and Chris Sells (January 2006)
In this article, the winning Windows Forms duo of Chris Sells and Michael Weinhardt team up again to explore lots of new features and additions to Windows Forms 2.0 that will let you build more flexible, feature-rich controls, get better resource management, more powerful data-binding abilities, and make your development life a whole lot more fun.

By Michael Weinhardt and Chris Sells (May 2005)
The upcoming version of the .NET Framework offers a host of enhancements an order of magnitude over and above existing versions. In particular, developers writing Windows Forms benefit from a variety of new and improved features targeting development, deployment, increased productivity, and auto-generated code. This article covers some of the key new features including designer enhancements, new controls, data binding, and deployment to give you a taste of what's to come.

By Michael Weinhardt and Chris Sells (May 2004)
This is the second of two articles discussing the extremely rich design-time features of the .NET Framework. Part 1 discussed the basics, showing you where to start and how to extend your control implementation through attributes and interfaces, as well as their effects on the property browser, code serialization, and other controls. Part 2 continues the journey by concentrating on design-time functionality that you can implement beyond your components and controls, including TypeConverters, UITypeEditors, and Designers. It would be impossible to cover everything you can do in two short articles, which is a testament to just how all-encompassing and flexible the design-time capability of the .NET Framework is.

By Michael Weinhardt and Chris Sells (May 2003)
Visual Studio .NET provides support for designing rich features into your controls and components, allowing you to set properties, set form placement, inherit from base classes, and much more. So how does Visual Studio .NET do all this? What does the Windows Forms designer do? What's the difference between a control and a component? How does Visual Studio integrate your controls so that they can access features of the .NET Framework?In this article, the authors answer these common questions by building a clock control and taking the reader along for the ride. In building the control, hosts and containers are illustrated, the property browser is explained, debugging is discussed, and a general overview of the design-time infrastructure is presented.

By Michael Weinhardt and Chris Sells (April 2003)
With the much-anticipated release of the .NET Framework 1.1, developers are eager to know what's been added to their programming bag of tricks. In this article, the author focuses on new developments in Windows Forms, such as namespace additions, support for hosting managed controls in unmanaged clients, and designer support for C++ and J#. Integrated access to the Compact Framework and new mobile code security settings also make this release noteworthy. Along with these features, the author reviews the best ways to handle multiple versions of the common language runtime and highlights some potential pitfalls.

By Chris Sells (March 2003)
Throughout this issue, you'll read all about the promise of Web Services and how the .NET Framework enables Web Service development. Many people will also be building their Web Services atop C++ code and frameworks like ATL Server, particularly when performance is paramount. In this article, the authors show how fully functional Web Services are built using ATL Server and Visual Studio .NET. Beginning with unmanaged C++ classes, they add ATL attributes that make the code work over HTTP.

By Kirk Fertitta and Chris Sells (December 2002)
Visual Studio .NET has lots of cool features. Obviously, it supports languages that target the common language runtime, like C# and Visual Basic .NET, and it lets you write CLR-managed code. But did you know that there are features of the environment itself, independent of the language features, that earn Visual Studio .NET the cool tool stamp of approval?In this article the authors count down their favorite environment features—the ones they think every developer will applaud. They include support for debugging stored procedures, project reference management, metadata in Class View, a richer immediate window, custom environment programming with macros, and more.

By Jon Flanders and Chris Sells (October 2002)
More ...
Popular Articles
Here we present techniques for programmatic and declarative data binding and display with Windows Presentation Foundation.

By Josh Smith (July 2008)
Animating with Silverlight is easier than you think. Here we create a 3D app that folds a polyhedron using XAML, C#, and by emulating the DirectX math libraries.

By Declan Brennan (April 2008)
Here the author answers questions regarding the Entity Framework and provides an understanding of how and why it was developed.

By Elisa Flasko (July 2008)
OBA solution patterns help architects and developers build Office Business Applications (OBAs). This article introduces the seven core OBA solution patterns and applies one to a real-world problem.

By Steve Fox (March 2008)
More ...
Read the Blog
The most fundamental form of Web testing is HTTP request/response testing. This involves programmatically sending an HTTP request to the Web application, fetching the HTTP response, and examining the response for an expected value. In the May 2008 issue of MSDN Magazine, Read more!
In the November issue of MSDN Magazine, Jeffrey Richter demonstrates some recent additions to the C# programming language that make working with the APM significantly easier. In the June ...
Read more!
The July 2008 issue of MSDN Magazine is now available online. Here's what's in the issue: Data Services: Develop ...
Read more!
The June 2008 issue features the first installment of a new MSDN Magazine column on software design fundamentals. We’ll discuss design patterns and principles in a manner that isn't bound to a specific tool or lifecycle methodology. In this issue, Jeremy Miller starts the Patterns in Practice column ...
Read more!
In the April 2008 issue of MSDN Magazine, Kenny Kerr introduced the Windows Imaging Component (WIC), showing you how you can use it to encode and decode different image ...
Read more!
A combination of the retained-mode graphics system and notification mechanisms such as dependency properties unleash the flexibility and power of Windows Presentation Foundation (WPF, allowing these objects to be targets of data bindings and animations. In the June 2008 issue of MSDN Magazine, Charles ...
Read more!
More ...
Smart Clients
Craft A Rich UI For Your .NET App With Enhanced Windows Forms Support
Chris Sells and Michael Weinhardt

This article discusses:
  • What's new in Windows Forms controls
  • Settings and resource management
  • Layout, resizing, and scaling
  • Data binding
  • ClickOnce deployment
This article uses the following technologies:
Windows Forms, Visual Studio, .NET Framework 2.0
Windows Forms 2.0 is far richer than any Windows application development platform that preceded it. You'll find improvements across the board, with a more dense and fully featured Microsoft® .NET Framework, tighter Visual Studio® integration with many new additional designers, a unified data binding model, and, the icing on the cake, ClickOnce for Web-style deployment.
Significant work has gone into the System.Windows.Forms namespace, the heart of the technology that comprises Windows® Forms. The usable surface area of the namespace, comprising public types (classes and enumerations), has increased by approximately 134 percent over the .NET Framework 1.1. There are 446 new public types; 113 existing types have been updated with new members and values; 218 types have been carried over from the original namespace; and no types have been removed. That's one major release. So major, in fact, that we don't have enough space to cover it all. However, Figure 1 gives you an overview. That's a lot of features! And they're all waiting for you when you create a new Windows Forms project.

Windows Forms Projects
Figure 2 Windows Forms Project Structure 
Whether you prefer C# or Visual Basic®, the first thing you'll notice when creating a new Windows Forms project is the new default project structure generated by the Visual Studio Windows Application project wizards, as shown in Figure 2. The updated structure represents several project enhancements we'll discuss.

Code Separation
One objective of the new default project structure is to remove code from the default Form1. The resulting trimmed-down implementation looks like this for C#:
// Form1.cs
partial class Form1 : Form {
  public Form1() {
    InitializeComponent();
  }
}
Visual Basic spent a little more time at the code-trimming gym:
' Form1.vb
Public Class Form1
End Class
You might be wondering where InitializeComponent went. In Windows Forms 2.0, designer-managed form code such as the InitializeComponent method is persisted to a new file, FormName.Designer.cs or FormName.Designer.vb. This separation, which is designed to keep developers and the Windows Forms designer from crossing swords, is enabled by new language support for partial classes in both C# and Visual Basic, as shown by the following code samples:
// Form1.cs (Developer-Managed)
public partial class Form1 : Form { ... }

// Form1.Designer.cs (Designer-Managed)
partial class Form1 {
    ...
    void InitializeComponent() { ... }
    ...
} 
Here's the Visual Basic equivalent:
' Form1.vb (Developer-Managed)
Public Class Form1
End Class

' Form1.Designer.vb (Designer-Managed)
Partial Class Form1
       Inherits System.Windows.Forms.Form
    ...
    Private Sub InitializeComponent()
        ...
    End Sub
    ...
End Class
If you're a C# developer, you might also wonder where the wizard-generated static Main method has gone. Since Main is the application-scoped, rather than form-scoped, it's been moved to its own file, Program.cs:
// Program.cs
static class Program {
  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main() { ... }
}
Visual Basic projects are configured to launch Form1 on application startup by default. If necessary, a custom Shared Sub Main entry point can be used. The result of code separation is that developers can focus on writing just the code needed to address their specific problem.

Improved Resource Management
The IDE itself has been updated for easier Windows Forms 2.0 programming. The Visual Studio Resource Editor receives a much needed facelift, with the major benefits being improved management and the ability to see what your resources will actually look like, as shown in Figure 3.
Figure 3 Visual Studio Resource Editor 
The Resource Editor now allows you to add new and existing files through a variety of mechanisms, including the dropdown list shown in Figure 3, pasting from the Clipboard, and dragging and dropping. Whichever mechanism you use, resources are automatically catalogued under one of these categories: Strings, Images, Icons, Text Files, and Sound Files. Another category, Other, exists for resource data like component-defined serialization of design-time data. To view each category, select the dropdown list in the upper-left of the Resource Editor. Each category adapts to the type of resource it contains to provide specialized views. For example, you can view all resource types other than strings via a Details, List, or Thumbnail view, just like in Windows Explorer.
Another important improvement is the ability to specify whether a resource is either embedded or linked. Embedded resources added to a project via the Properties Editor are stored in a project-wide resource (.resx) file. Linked resources (the default for resources other than strings) means Visual Studio references a file outside the project system, making it easier for different people to manage resource data (which you'd want for graphics and sound), while allowing developers to do what they do best: build applications. And Visual Studio comes through for developers on that front as well.
Consider what was previously required in Windows Forms 1.x to retrieve string resources from your code:
// Load string resource from project resource file
Assembly assem = Assembly.GetExecutingAssembly();
ResourceManager resman = new ResourceManager("MyApp.Resource1", assem);
string myStringResource = resman.GetString("MyString");
Now consider the simplified and strongly typed approach enabled by Windows Forms 2.0:
// Load strongly typed string resource
string myString = Properties.Resources.MyString;
Windows Forms now generates a class, Resources (located within the ProjectName.Properties namespace), which exposes each resource via a strongly typed static (shared) property. Now, any resource type—including icons, images and sounds—can be easily retrieved from code as strings:
// Strongly typed resources of all kinds
string myString = Properties.Resources.MyString;
Icon myIcon = Properties.Resources.MyIcon;
Image myImage = Properties.Resources.MyImage;
UnmanagedMemoryStream mySound = Properties.Resources.MySound;
Any additional .resx files you add to your project will also cause strongly typed wrapper classes to be generated.

Improved Setting Management
There's a new Settings Editor, available from a project's property pages, which allows you to add settings to one of two scopes: application and user. Application settings, such as database connection strings and URLs, are permanent settings that don't change after an application is installed. User settings, such as those found in the Tools | Options menu, are default settings that users can change after installation. Figure 4 shows the Settings Editor in action.
Figure 4 Visual Studio Settings Editor 
The Settings Editor deploys both application and user settings with an application's configuration file (ApplicationName.exe.config). And, like resources, Windows Forms generates a strongly typed wrapper class, located in the ProjectName.Properties namespace. Application settings are implemented as read-only properties while User settings are implemented as read/write properties. Both can be programmatically inspected or updated via a generated static (shared) Default property:
// Inspect an Application-scoped setting
string myAppSetting = Properties.Settings.Default.MyApplicationSetting;

// Update a User-scoped setting
Properties.Settings.Default.MyUserSetting = "myNewUserSettingValue";
Since users expect their settings changes to be applied from one application session to the next, changed user settings need to be saved at the end of one session and reloaded at the beginning of another. While user and application settings are loaded automatically at the beginning of each session, you must manually save user settings at the end of a session by calling the Save method, exposed from the generated Settings class as shown here:
void OptionsForm_FormClosing(object sender, FormClosingEventArgs e) {
    // Save user settings for next time
    Properties.Settings.Default.Save();
}
Application settings are read-only, whereas user settings are not and must be saved to a file other than the application configuration file. For this reason, Windows Forms persists user settings to user.config, which is located in a Windows logo-compliant file system location that's tied to the user. The path to that file varies depending on certain conditions, such as whether roaming is enabled. The following location is used by standalone applications:
%InstallRoot%\Documents and Settings\UserName\
    Local Settings\Application Data\ProductName\
        ApplicationName.exe_Url_UrlHash\AssemblyVersionNumber
Sometimes, users change settings to values they are not happy with, but can't remember what the previous settings were. In this case, you can provide a mechanism to revert to the last saved settings by calling the Settings object's Reload method:
void reloadSettingsButton_Click(object sender, EventArgs e) {
    // Revert back to last saved user settings
    Properties.Settings.Default.Reload();
}
Second, if user settings are completely overcome, you can revert to an application's initially deployed settings: the values entered into the Settings Editor. Retrieving them requires calling the Settings object's Reset method:
void resetButton_Click(object sender, EventArgs e) {
    // Revert back to default installed user settings
    Properties.Settings.Default.Reset();
}
User settings are managed in such a way that, if the user.config file is deleted, the default values for those settings are loaded into the next application session.

System.Windows.Forms.Form
Whereas Visual Studio is the number-one tool for building Windows Forms applications, System.Windows.Forms.Form is the number-one class. As you would expect, this class has been updated, and now includes the addition of key new members listed in Figure 5. By far the most interesting of the new members are those dealing with layout.

Snap Lines, Margins, and Padding
You can use snap lines to align controls as you drop them onto forms and drag them around. When dragged onto a form, snap lines manifest as one or more sticky lines that guide controls to alignment with other controls in close proximity, both horizontally and vertically, to common text baselines and text margins (see Figure 6).
Figure 6 Snapping Lines 
Besides being aligned to one another, controls need to be nicely spaced in relation to one another. While snap lines don't cater to spacing, two new properties found on Control do: Padding and Margin. Padding is the internal distance in pixels from the edge of a form or control's client area that child controls (and also things like text and images) can't intrude on. Margins are the external distances in pixels from control edges that other controls can't intrude on. As controls are dragged, a blue line is displayed between controls and the form when the distance between them is the sum of their Margins and Padding. Figure 7 shows Margins and Padding being used to determine when controls are correctly spaced. Both Padding and Margin properties can be specified for all edges at once or on an edge by edge basis.
Figure 7 Use of Margins and Padding 

Automatic Resizing and Scaling
Since snap lines, margins, and padding are merely guides, they can be ignored, leading to the possibility that controls become either partially or fully hidden as they are moved or resized. You'll need to resize the container control to show the hidden parts of the resized or moved control, a tedious process when many controls are involved. Instead, you can use the AutoSize and AutoSizeMode properties. AutoSize is a Boolean property that, when set to true, instructs a control to resize automatically to fit its contents. The AutoSizeMode property tells the control how to resize, as specified by the AutoSizeMode (System.Windows.Forms) enumeration's GrowOnly and GrowAndShrink values.
GrowOnly specifies that a container should automatically resize if the new size of the contained control will be either the same size or bigger than its size. GrowAndShrink specifies that a container should both increase and decrease in size in response to contained controls resizing and moving, as illustrated in Figure 8.
Figure 8 Automatic Resizing with GrowAndShrink 
Automatic resizing is triggered when the edges of a control come close enough in proximity to the host container's right and bottom edges that their margins overlap. A variety of controls support AutoSize alone, or AutoSize and AutoSizeMode together. Some controls, like Forms, do implement both, but will only use them at run time. You'll need to experiment with each control in order to determine its level of automatic resizing support.
Besides being able to automatically resize to fit content, forms and controls are also able to automatically resize across DPI settings while maintaining consistent proportions with respect to size and position. Two key elements are required to maintain the same proportions, or scale, across multiple DPI settings. The first tells the form to automatically scale. The second tells the form what scale factor to apply to the size and position of the form and its controls. By default, forms automatically scale via their AutoScale property, which is set to true. The scale factor, specified by the AutoScaleMode property, can be one of the following values:
enum AutoScaleMode {
    None = 0, // Don't scale
    Font = 1, // Scale in relation to font size (default)
    Dpi = 2, // Scale in relation to dpi
    Inherit = 3 // Inherit container's AutoScaleMode
}
The default is Font, meaning the scale factor, is based on the ratio between the average widths and heights of the default system font when the form was created and when the form executes. For example, if a form was created under Windows XP Normal fonts (96 DPI), the default font would be 8.25pt MS Sans Serif with an average width and height of 6x13. This information is stored in a form's AutoScaleDimensions property automatically by the Windows Forms Designer:
// AutoScalingForm.designer.cs 
partial class AutoScalingForm {
    ...
    void InitializeComponent() {
        ...
        this.AutoScaleDimensions = new SizeF(6F, 13F);
        ...
    }
}
If the form were subsequently reopened or executed under Large fonts (120 DPI) where the default font will be 7.8pt MS Sans Serif, the average width and height of the font increases to 8x16. The form notices the difference between the AutoScaleDimensions and the current scale dimensions, and it adjusts the width, height, and position of its controls by the calculated difference. This keeps the general look of the form roughly the same, no matter what the system font settings are. The same behavior is consistent from within Visual Studio, too.
Whereas AutoSizeMode.Font causes scaling to be based on the difference of a font across DPIs, AutoSizeMode.Dpi causes scaling to be based purely on the difference across DPIs. Figure 9 compares the two modes.
Figure 9 AutoScaling from 96 DPI to 120 DPI 
The real-world difference between AutoScaleMode.Font and AutoScaleMode.Dpi is that the former won't scale at the same rate as the latter since proportional fonts will scale differently than pure linear DPI scaling, especially from one language to the next. AutoScaleMode.Font is the default because it's the most robust option.

TableLayoutPanel and FlowLayoutPanel
While snap lines, margins, padding, automatic resizing, and automatic scaling comprise a useful layout toolbox, they can't easily support more complex scenarios where resizable dialogs host nontrivial numbers of controls. In anticipation of such scenarios, Windows Forms incorporates two new layout controls: TableLayoutPanel and FlowLayoutPanel.
TableLayoutPanel supports HTML-style table layout. You can define rows and columns that can be configured to automatically size in one of three ways:
  • AutoSize: automatically resizes to fit its contents
  • Percent: size is a percentage of the total height or width of a TableLayoutControl
  • Absolute: fixed size in pixels
Rows and columns can be merged and resized through the Windows Forms Designer. Each cell can contain just one control whose position within the cell is a function of docking and anchoring. Figure 10 shows an example of the TableLayoutPanel in action. It also shows both the OK and Cancel buttons hosted within a nested TableLayoutPanel, which is a useful technique when you need more than one control per cell.
Figure 10 TableLayoutPanel Control 
FlowLayoutPanel supports HTML-style flow layout. You can tell a FlowLayoutPanel the direction in which contained controls should be nudged during resizing by setting its FlowDirection property to one of four values: LeftToRight, TopDown, RightToLeft and BottomUp.
As with Web pages, a FlowLayoutPanel may be resized so that contained controls simply cannot be moved anymore, leaving them partially or fully covered by either vertical or horizontal edges of the FlowLayoutPanel, or both. In these situations, you can set the AutoScroll property to true to provide vertical and horizontal scroll bars if needed.

Controls and Components
Windows Forms 2.0 comes complete with a range of new controls and components that focus on filling holes in previous toolboxes, including MaskedTextBox, WebBrowser, and BackgroundWorker. Additionally, there are a variety of improvements across the control and component libraries, including the ability for common controls to visually adapt to the current Windows theme on the fly, and designer support for smart tags to enable more rapid and focused configurations for developers.

MaskedTextBox Control
The MaskedTextBox control is designed to provide a more informative and accurate data entry experience by guiding users with hints as to the type and shape of data to be entered using a mask (see Figure 11). There are a lot of mask characters; if you need help building and testing a mask, you can open the MaskedTextBox control's Input Mask Editor from the Properties window.
Figure 12 MaskedTextBox 
By default, non-mask characters, such as parentheses, hyphens, and spaces, are treated as literals and are shown at run time to describe the shape of the required data, while all mask characters are replaced by a prompt character at run time (underscore by default, and only shown when the MaskedTextBox has the focus, as shown in Figure 12). MaskedTextBox implements a wide variety of properties, the most interesting of which are listed in Figure 13. MaskedTextBox is a highly configurable control you should consider when giving users a more informed data entry experience.

Web Browser
Whereas Windows Forms applications have always been able to support Web browsing using COM controls via interop, the programming experience was a little messy. The new Web Browser control, however, provides a managed way to easily augment Windows Forms applications with Web browsing capabilities, as shown in Figure 14.
Figure 14 WebBrowser Control in Action 
Navigating to a URL is as simple as invoking the WebBrowser's Navigate method:
void goButton_Click(object sender, EventArgs e) {
    // Navigate to URL
    this.webBrowser.Navigate(this.urlTextBox.Text);
}
When the WebControl has navigated to a new page, it fires the Navigated event before it begins downloading the page. WebControl also fires the ProgressChanged event by which you can monitor page download progress. And, of course, WebBrowser provides methods to handle the several standard navigation options found in any browser:
this.webBrowser.GoBack();    // Navigate to previous page in history
this.webBrowser.GoForward(); // Navigate to next page in history
this.webBrowser.Stop();      // Stop loading of the current page
this.webBrowser.Refresh();   // Reload the current page
this.webBrowser.GoHome();    // Navigate to home page

BackgroundWorker Component
Windows Forms applications often need to perform long background operations such as searching. The solution is to use multithreading support in .NET to spin off worker threads to execute the long-running operations asynchronously, which allows the main UI thread to continue servicing user requests. But coding worker threads can be hard and time-consuming.
In Windows Forms 2.0, however, you can use BackgroundWorker, which encapsulates the complexities of worker thread creation and management into a single component that you can drag onto a form in Visual Studio. Invoking BackgroundWorker.RunWorkerAsync causes a worker thread to raise the BackgroundWorker.DoWork event you handle to execute your long-running operation code. RunWorkerAsync and DoWork are shown in the code in Figure 15.
BackgroundWorker ensures that data you pass between the UI and worker threads is done so in a thread-safe manner. BackgroundWorker also supports progress reporting and cancellation, and, because it's a component, it allows you to configure this functionality from the designer.

AutoCompletion
One improvement that applies to several controls is auto-completion. This is implemented on ComboBox, TextBox, ToolStripComboBox, and ToolStripTextBox. It comprises three properties: AutoCompleteMode, AutoCompleteSource, and AutoCompleteCustomSource. AutoCompleteMode allows you to set the auto-completion style from an enumeration of the same name:
enum AutoCompleteMode {
    None = 0,         // No auto-completion (default)
    Suggest = 1,      // Possible matches chosen from drop-down list
    Append = 2,       // Possible matches appended to text while typing
    SuggestAppend = 3 // AutoSuggest and AutoAppend combined 
}
An option other than "None" requires you to set the AutoCompleteSource property to one of several system auto-completion sources specified by the AutoCompleteSource enumeration:
enum AutoCompleteSource {
    FileSystem = 1,       // File system
    HistoryList = 2,      // All URLs from History list
    RecentlyUsedList = 4  // All URLs from Recently Used list
    AllUrl = 6,           // HistoryList + RecentlyUsedList
    AllSystemSources = 7, // FileSystem + AllURL
    FileSystemDirectories = 0x20, // File system folders
    CustomSource = 0x40,  // AutoCompleteCustomSource
    None = 0x80,          // No source (default)
    ListItems = 0x100     // Items in control list (combo boxes only)
}
Choosing CustomSource instructs the ComboBox that you will provide auto-completion options from a collection of items stored in the AutoCompleteCustomSource property. ListItems specifies the source to be the items stored in the ComboBox's List property.

Strip Controls
Deserving special mention due to their sheer coolness are the strip controls. MenuStrip, ToolStrip, StatusStrip, and ContextMenuStrip add a contemporary flavor to your user interfaces, as illustrated in Figure 16.
Figure 16 Strip Controls 
The new strip controls succeed MainMenu, ToolBar, StatusBar, and ContextMenu (retained in Windows Forms 2.0 for backwards compatibility) and improve on them in several ways, including:
  • A consistent API to all strip controls
  • Improved design-time experience
  • Dragging between form edges
  • Office 2003 and Windows Themes sensitivity
  • Can host a rich set of child controls, including dropdown lists, labels, menus, and textboxes
  • Simplified custom painting support
  • Integration with the settings system
  • Form integration with the MainMenuStrip property, and control integration with the ContextMenuStrip property
Strip controls offer a large degree of design-time support, the most important of which is to simplify the addition of items to each strip control. The items that can be added to a strip control depend on the purpose of the strip control, as outlined in Figure 17.
Strip control items can be added, updated, and deleted via the Properties window, with smart tags, or visually from the design surface. Both MenuStrip and ToolStrip provide an "Insert Standard Items" option to pre-populate the controls with items for typical commands such as Open, Save, Save As, Cut, Copy, and Paste.
The strip control Properties window and smart tag support enable a variety of other interesting configurations, the most important of which are controlled by the properties listed in Figure 18. Apart from the standard properties you would typically find on controls, such as Enabled, Visible, Checked, and BorderStyle, strip controls offer some additional properties, outlined in Figure 19.

Strip Container
One of the key features of the strip control suite is the ability to drag them from one edge of a form to another. While strip controls are docked to form edges by default, docking doesn't provide the smarts to support dragging. Instead, this behavior is added to a form with a ToolStripContainer control, shown in Figure 20.
Figure 20 ToolStripContainer Control 
Because ToolStripContainer is a container control that provides form-wide strip control semantics, it needs to be added to a form before any other controls. Controls are then added to its content panel, while strip controls are added to one of four special panels. Each panel can be expanded or collapsed to accommodate the strip controls you'd like against each form edge. You can also hide/show panels as needed by setting the ToolStripContainer's TopToolStripPanelVisible, RightToolStripPanelVisible, BottomToolStripPanelVisible, and LeftToolStripPanelVisible Boolean properties.
At run time, you can drag strip controls between the edges of the form for which panels are visible. Only strip controls that have a drag grip can be dragged. And if two or more tool strip controls reside in the same tool strip panel, they can be repositioned amongst themselves as required by the user. Since tool strips can be moved to new positions by users at run time, users will expect them to be in those positions from one application session to the next. For this, you use the ToolStripManager class (from System.Windows.Forms), which nicely implements the static (shared) LoadSettings and SaveSettings methods.

Data Binding
In Windows Forms 2.0, data binding is much richer than before thanks to the new BindingSource component whose primary role is to upgrade non-data binding-savvy data sources with richer data-binding capabilities. This enables the unification of disparate data sources and, in addition, facilitates the creation of a single client code pattern for any type of data source.
Figure 21 Data Sources 
A data source can be easily added to a project using the Data Source Configuration Wizard (Data | Add New Data Source). From there, you can create data sources for databases, Web services, and objects. If you create a data source from a database, a new strongly typed DataSet is added to your project and can be viewed from the new Data Sources window (Tools | Data | Show Data Sources), shown in Figure 21.
The Data Sources window provides tool strip items that allow you to add new data sources and, if a data source is a strongly typed DataSet, edit, reconfigure, or refresh them. When dropped onto a form, controls like DataGridView will automatically prompt you to select a data source or create a new one.

BindingSource
When you think "data source," you are likely to think of the most popular type: the typed DataSet. But data sources come in many shapes and sizes, including tables, XML, and .NET-based objects. All of these could be bound to in Windows Forms 1.x, with differing levels of data binding integration. This forced developers to spend a nontrivial amount of time updating their data sources to achieve higher levels of data binding integration by implementing IBindingList. The Windows Forms 2.0 BindingSource component addresses this problem by being able to consume any list type and reexposing these as IBindingList list data source implementations. Additionally, item types can be handed to the BindingSource component, which turns them into an IBindingList implementation for you.
To configure a BindingSource to consume the desired data source, drop one onto your form and set its DataSource and DataMember properties appropriately. Here's an example of BindingSource consuming a typed DataSet:
public partial class DataBindingForm : Form {
    public DataBindingForm() {
        ...
        // Consume a type data set
        this.bindingSource.DataSource = this.northwindDataSet;
        this.bindingSource.DataMember = "Employees";
    }
}
The BindingSource component