|
|
YOUR FEEDBACK
|
TOP MICROSOFT .NET LINKS Windows Forms Controls
Cover Story: Unlocking the Inner Secrets of WinForms
Windows Forms Features Explored
By: Adam Calderon
Nov. 22, 2005 06:15 AM
Digg This!
The new version of Windows Forms in .NET 2.0 brings some exciting and much-needed enhancements that not only allow for more productivity, but also allow for creating some extremely professional looking applications that have the look and feel of many of the office applications we use every day. The goal of this article is to introduce many of the new features starting at the base level and building up, much as you would create an application, detailing each feature and how the features can help you.
The use of partial classes, a new feature of .NET 2.0, now makes working with Windows Forms designer-generated code much easier. In previous releases your code and the designer code lived in the same file, thus making your development effort a lot less manageable. Now when you add a form to your project you get two generated files: one, [Form Name].Designer.(vb or cs), which contains the designer generated code, and another, [Form Name].(vb or cs), which is created for your code. The new Application Settings feature, a replacement for dynamic properties, enables developers to easily create, store, and maintain both application and user data on the client. This feature eases the development experience by providing a built-in framework for working with application data such as Web service locations or database connection strings, and user data such as the user screen positions or button positions on a toolbar. The steps to implement application settings in your application are very simple and require very little to no coding at all. It is as simple as selecting a form or control, opening the simple designer that is under the (ApplicationSettings) groups (PropertyBinding) entry in the properties window, selecting a property to persist, naming the entry, and setting its scope to either application or user. The persistence model for application settings, which is also handled for you, relies on XML and uses either the application configuration file and the <applicationSettings> element for read-only access to application-specific data or the user.config file, which is unique for each user, and the <userSettings> element for read/write access to user-specific data. The enhancements to Data Binding (see Figure 1) are enormous. From the new wizards and controls to the ability to retrieve data from a variety of data sources, everything is much more integrated than in previous versions. The first thing you will notice is the new Data Sources window that provides a common point of reference when working with data throughout your application. The window relies on an easy-to-use wizard to create data sources from a database, local database file, Web service, or custom business object, and adjusts the user's experience depending upon what type of data you are trying to retrieve. Once you have created a data source you can then use that data source as the basis for data in your form. This can be done in a number of ways, such as dragging a field from the data source field list onto your form and having the designer create the field automatically, or laying out your form and then connecting the field to your form control. Either of these methods creates a series of controls on your form that create a foundation for a new level of indirection and type-safe access to data that is the cornerstone of the new data binding enhancements. The main control that gets created is the DataSource control, which is the common data source for all data bound controls. This control abstracts the complexities of the underlining data, thus providing a common place for navigating, sorting, filtering, and updating data-bound data, and also manages the data concurrency so that all common bound controls show the same data. If you are working with a database, the TableAdaptor control will also be added to your form during this process. This control provides communication between your application and the database and can be considered as a DataAdaptor with a built-in connection object and the ability to contain multiple queries. Each query contained in the TableAdaptor is exposed as a type-safe method and is required to return the same schema. Finally, the BindingNavigator control is added to your form, in the case of working with a database, which works in conjunction with the DataSource control to assist in navigating and manipulating your form data. The BindingNavigator controls UI is composed of a series of ToolStrip buttons, text boxes, and static text elements for most of the common data-related actions such as adding data, deleting data, and navigating through your form data. As you can see, many of the complexities of the previous versions of Data Binding have been abstracted for you, thereby allowing you to be more productive when creating data-driven applications. Form Layout, Navigation, and Control-Interaction Enhancements The layout of controls on a form has now been enhanced by the introduction of the Snaplines designer feature, the FlowLayoutPanel control, the TableLayoutPanel control, and the SplitContainer control. The Snaplines designer feature aids in the layout of absolute positioned controls by automatically displaying anchor lines as you move your control in the vicinity of another control, which makes it extremely easy to line up and space your controls. The logic for the appearance of the anchor lines is a combination of the values of the new margin and padding properties now on all controls and the Windows Design Guidelines for the spacing of controls on a form. The FlowLayoutPanel control is a new container control that bases the layout of controls contained in it on relative positioning instead of absolute positioning, which is the case when you drag a control onto a form. This control allows you to determine how the controls inside of it are displayed either horizontally or vertically based on the FlowDirection property, and if the contents are clipped when the control's dimensions are reduced based on the WrapContents property. This control work very well in situations where you want to add buttons dynamically at run time to a preexisting area and have them arrange themselves automatically. The TableLayout control, which is also a container control, brings some of the layout behavior that HTML tables bring in, allowing the user to place controls inside of the grid. Just as in HTML, the rows and columns can shrink or grow depending on changing content and screen dimensions. The RowCount, ColumnCount, and GrowStyle properties control just how the grid will respond to the contents added to it and the RowStyles and ColumnStyles properties control how the rows and columns behave when the page is drawn. This control can be very helpful in situations where you are laying out a form that requires the controls to respond appropriately to changes to the size of the screen. The last control I will talk about in this category is the SplitContainer control, which is a replacement for the Splitter control. This control is a composite control consisting of two panes and a moveable splitter bar, and the splitter bar's vertical and horizontal orientation is adjustable based on the Orientation property. This control enables you to create complex user interfaces similar to Outlook with one panel determining what is displayed in the other panel. The process of quickly finding a control on a form has historically been slow and there has been no support in the Windows Form designer to navigate through the controls easily until now. The Document Outline window has been added to the forms designer, thus enabling form-control navigation just as in HTML pages. The contents of the form are now in a tree view, giving you a hierarchical view of your controls based on the parent-child relationship of the controls inside of the form. New ToolStrip Family of Controls DataGridView Control Conclusion References
MICROSOFT .NET LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
||||||||||||||||||||||||||||||||||