This article is based on the preview before the release of Microsoft Visual Studio 2005, before the code "Whidbey". All of these information may change in the official version. The content discussed herein:
New content about Windows Form Controls
Use 'theme'
Binding and display data
Other data detail characteristics
This article uses the following techniques: C # and Windows Forms Microsoft .NET Framework 1.0 Edition is really good to meet our requirements. .NET has important significance in the following two aspects that not only fundarately changed the developer to build a method of publishing a Windows application, but also created a huge technical platform with very good telescopic characteristics, Visual Studio2005 is a very Good example, it is very good in terms of user-specific and improved functionality. These changes affect the Windows form subset in the Microsoft .NET framework, extend from the core System.Windows.Forms namespace to a variety of supportive technologies, both of which have new, including ADO .NET, ObjectSpaces, and Clickonce deployment. In various aspects of Visual Studio 2005, it can be found in production efficiency, including enhanced integrated development environments, improved controls and data designers, and code generators. Since you don't have to manually write a variety of booking format, the code writes madness may be frustrated, and we can have more time to enjoy our lives. Some important work in System.Windows.Forms has been done in System.Windows.forms, and the Windows Form is included in the exciting new technologies. At the same time as I wrote this article, the number of namespaces and common types and members of the publication increase of 67% and 127% respectively, which undoubtedly marks Visual Studio 2005 is a superior product. Of course, we don't have enough space in this article to tell everything, and Figure 1 shows us a major improvement overview. These new and strengthened improvements have broad coverage, such as better theme support, improved data binding And the GridView control.
Category Description Layout Controls SplitContainer, FlowLayout, and TableLayout Container is used to manage controls in design and runtime management controls. Data Binding control GridView controls are used to enrich the form of expression, query, and processing methods. DataContainer is used to simplify data binding and data binding user interfaces, supporting user interface design and master-detail user interface design for VCR styles. User Interface Construct Components MainMenu Components Now supports menu items to add images. The WinBar control provides toolbars as Microsoft Office. The WebBrowser control is a managed browser that encapsulates Shdocvw.dll. Controls and Components ControlarRay enables a single interface to get a recovery management to manage many controls, they can make different types. ComponentArray is a Nice method that instead of Controlarray, which faces components. Asynchronous call Supports components work in background work overwrites the creation and management of the working thread (technology is not implemented from System.Windows.forms, but the Windows form can be implemented). The sound file is loaded in sound components. Image file is loaded in the picture box control. Basically improve the support of the text box and composite list box control, which automatically completes many system resources including IE browsing history records and starts | running commands. The composite list box and the list box control have added support for formatting the most entered list items. Figure 1 New Windows Forms Windows Topics Support When you create a new Windows Formwork like past, you will find a new change: the default Windows topic support. A Windows theme is a group of personalized user settings, which showcase the look of the Windows user interface. You can specify a desktop topic by clicking the right mouse button on the desktop and selecting the Properties | Theme "property page in the pop-up" Properties dialog "property page. Because the Windows theme is specified by the user, the Windows Form is responsible for expressing it. Although the existing version of the .NET framework supports Windows theme, 1.0 version requires developers to add a file with special names in the specified location of the file system. 1.1 version is supported by providing the Application.enableVisualStyles method and sets the FlatStyle property value of each control to "System" to simplify the version of the version of the version. Visual Studio 2005 will further improve this process, and call the enablevisualstyles method when establishing a new Windows Formwork.
[Stathread]
Static void main () {
Application.enablevisualstyles ();
Application.run (New Form1 ());
}
...
} In the past, set the FlatStyle attribute value of the control to "System" means that the operating system determines the appearance of the control display. Now, when the FlatStyle property is set to the default value "Standard", most of the controls of Visual Studio 2005 will present themselves based on the Windows topics currently being used. This is quieted by the system settings and then saves your settings in the designer basically. Regardless of the FlatStyle property or "System" or "System", the form will be dynamically reactively responded to the change in the subject, but does not need to write a line of code, which is advantageous for the developer. Control layout and configuration support Windows topics only need to create an engineering or form, and put it in need control. However, the control on the form is layout, and it is configured to work, especially those complex forms. For the sake of simplicity, the Windows Form Designer has added some new features, the purpose is to reduce the design time consumed by these trivial things. These features include adsorption alignment, editing attribute patterns, and intelligent tags, which make the operational control easier. You can still use the Visual Studio layout toolbar to level or vertically align, you only need to manipulate those controls on the form. In addition, you can use adsorption to reach the same effect as dragging control while avoiding waste of design time brought by selecting controls and toolbar buttons when using the layout toolbar. Adsorption alignment is a blue line with viscous blue lines, and the control is aligned with adjacent controls under the guidance of these lines. Figure 2 Editing the property to another new feature, edit the property mode, allow you to pass controls with Tab keys and directly change their properties directly on the page. First click in the context menu of the Windows Form Designer, click on the menu item that is the same name to make the edit attribute mode activation. The next step is to traverse the control and modify the properties in accordance with your requirements. The process is shown in Figure 2. After the editing is complete, click "Return Layout Mode" to return to normal editing mode. Setting attributes is a simple way to change controls. Use another more appropriate control to completely replace the current control, you need to delete this control, then drag a new control into the form and reconfigure it. Close to this complex multi-step design task, the smart tag is actually used, it combines multi-step tasks when designing, and displays the menu item icon in the vicinity of the relevant controls as its tag, intelligent tag can also handle simple design. Time tasks often happen, for example, change its "text" attribute when moving a text box into a form. Another improving of the control and data binding integrated development environment is that the Windows form in Visual Studio 2005 provides new controls and improves popular older controls such as text boxes and composite list boxes. Figure 3 shows a small browser created with new controls and improvements in the use of the control, creating the code they need than the code than in the last version of the Windows Form. Figure 3 This simple example of using a new control web browser shows how to create rich programs in Visual Studio 2005, while reducing code writing. For example, designing this fully fully spent approximately 10 minutes and only writes 85 lines of code to achieve traditional all web browsing events, which also implements the URL access history. The actual work of web navigation and HTML presence is done by the WebBrowser control in the right block container. Split bars and left and right blocks are provided by a splitcontainer control. The composite list box shown in Figure 3 shows the new automatic completion support. Automatic completion function is implemented by 3 properties, first is AutoCompleteMode, which allows you to choose a style enumeration value to set automatic completion styles: Enum autompletemode {
None = 0x0, // no autocompletionAutosuggest = 0x1, // Possible matches chosen from drop-down list
AutoAppend = 0x2, // Possible Matches
// Appended to Text
// While Typing
AutoSuggestAppend = 0x3 // AutoSuggest and
// AutoAppend Combined
} In addition to selecting "None", other options require you set the autocpetesource property, which is the system pre-set AUTOCOMPLESOURCE enumeration value: Enum autompletesource {
FILESYSTEM = 0x1, // File System
HistoryList = 0x2, // all Urls from History List
RecentlyusedList = 0x4, // all Urls from Recently Used List
Allurl = 0x6, // HistoryList RecentlyUsedList
Allsystemsources = 0x7, // FileSystem Allull
Customsource = 0x40, // AutoCompletecustomsource
None = 0x80 // no source
} Setting a custom source composite list box requires us to provide automatic completion options that can come from a collection of elements stored in the AutoCompletecustomsource property. Currently, the composite list box and the text box are only available to provide auto-completion functions. Most of the controls in the GridView Toolbox support data binding, bind a wide variety of data sources through the underlying data binding component. In many cases, in particular prototype and rapid development, data binding is critical. The Windows Form Development Team clearly enhances the data binding namespace, including GridView and DataContainer, which enhances the design support for rapid development. These features make the same easy to develop user interfaces of a sub-area style or a user interface of the table style. Sometimes the user interface of the table style is more suitable for displaying the binding data, and on the other hand, Microsoft contains the DataGrid control in its previous version. Net framework. For Visual Studio 2005, the Windows Form Development team responded to the community's feedback on DataGrid and decided to construct a new table control, System.Windows.Forms.GridView (see Figure 4). Figure 4 Gridview Columns may be DataGrid and Gridview The most obvious difference is the object model of GridView. It has been abstracted as a column, row, natural table structure, allowing developers to manipulate each of them through a large number of intuitive positioning functions Cells, including the following:
By styles, formats, layouts, and selection supports rich custom user interfaces with DataGrid's ability to display more types of data compared to DataGrid, a group of more rich types, including images. Such exciting features such as frozen columns (similar to Excel) such a reorder (similar to the Outlook). The child controls have more than 100 events combined with extensive design experience in navigation, editing, verification, self-painting, and error handling. These new features allow us to quickly customize controls without writing a lot of code, actually The method, attributes, and events of the GridView will be stuffed into the GridView's specific encoding. One of the examples is to select a row by clicking on the cell in the DataGrid, and now exposes in a GridView's SelectionMode property. Of course, there is no control is perfect. When they exhibit deficiencies, developers should rely on their extension characteristics to combine controls with customizen. The underlying implementation of the GridView control is based on a variety of cells, rows and columns, you can inherit and expand. In general, GridView as a table style control is more eye-catching than DataGrid. Typened Dataset GridView controls are one of the controls that can bind arrays, collections, and types of controls. The advantage of the type of data set is that: .NET Framework allows the control to bind to the designer to help developers see the designed user interface. GridView implements this function by automatically generating data of each field in the data source during design. Visual Studio 2005 enhances the type of data set to make our lives easier. You will reduce the time on the design form, and the Type Dataset now can now complete the metadata in the data source, including foreign key constraints and increment seeds, and step control. As shown in Figure 5. Figure 5 Default Type Data Set Designer also generates a populated query that encapsulates the SELECT statement of the query related table and implemented in the same name method in the type data set. Sometimes, the system initially specified SELECT, INSERT, UPDATE, and DELETE statements are not easy. For example, the fill method will return all employee information, and many times you just need to return an employee information. In this case, using your own query statement and fill it is wise. Type Dataset Designer allows you to add your own query statement, to be implemented by selecting "Add" | Query in the context menu in the appropriate table. The Dataset Query Wizard dialog helps you construct your own query statement, and then update by the new data. When you complete the configuration of the type data set, you will bind him into one or more controls in the user interface. In Visual Studio 2005, type data sets can be bind them into controls that implement data sources and data member properties, without having to add data set objects into the form. DEFAULTINSTANCE Anyone who used to use the type of dataset knows that it is generally necessary to use a new type of data set only in one place in the application. Because the Windows Form Development Team understands us and wants us to make it easier, they have set a static property defaultInstance in each generic type data set, and get this single real example by calling it. Implement the following: public static employeetds defaultinstance {get {
IF (_defaultinstance == null) {
_DEFAULTINSTANCE = New northwind ();
}
Return_DefaultInstance;
}
}
You can use the defaultinstance properties like this: public class form1: system.windows.forms.form {
...
PRIVATE VOID FORM1_LOAD
Object sender, system.eventargs e) {
// load data
Employeetds.defaultinstance.loaddata ();
}
...
}
The data binding control uses the type name of DEFAULTINSTANCE to set their data source properties, and the type name is the form of "Engineering Namespace. Type Data Collection", and then the steps specifying the data will remain unchanged. The DataContainer control GidView control is an example of a complex binding control. It means that the control knows how to manage data binding to support query, insert, update, and delete operations. Instead, simple data binding controls do not know this, you need to implement the same functions as complex binding controls through the Data Source Binding Manager, especially with the user interface with that VCR style control. When you prefer a list of data instead of data in the table format, you can use a simple data binding control. This method requires you to manually add a range of appropriate controls into the form, such as tags and text boxes, as shown like Figure 6. Figure 6 Basic User Interface When you can manually implement such a fine form, you can also bind a Type DatotAding at once through DataContainer in Visual Studio 2005. Only need to simply select the menu item named this form from the DataContainer's smart tag. This feature will automatically generate all control zones based on the selected data source. Moreover, DataContainer will load and save this data, and the Navigation of the VCR style will be added by default without writing code. The result is shown in Figure 7. Figure 7 User interface with VCR controls, user interfaces, if your interface needs to change and you find the user interface of the table style, you can use Datacontainer to complete such a daunt task, you only need to choose from DataContainer Intelligent tag option. The designer deletes all existing controls, which in turn will be a GridView in a DataGrid (in the future version of Visual Studio). Master-detail binding multi-function DataContainer is also a powerful tool to build Master-Detail user interfaces, which provides a form-based visual effect to display a pair of relationships that are often used in relational databases. For example, there is a display of the employee-order relationship, we only need to simply add the order table to the type data set. Figure 8 Master-Detail Form Since we have generated a master user interface (as shown in Figure 7), we will do next to drag a GridView to the form and set its data source attribute to Datacontainer. The data member property is set to an order - order detailed relationship (here the order - the foreign key constraint), the result is like Figure 8. Clickonce Deployment When you set all the controls in the form and write the code that makes them work together, you will deploy this application. Deploying an enterprise-class Windows Form application for a large number of users will face a severe challenge for installing and versioning, so the developers of the previous generation are more willing to abandon the rich Windows user interface and turn to the web application and enjoy The convenience of the deployment brought. In .NET, Microsoft started to create a underlying structure, which makes it easy to publish the Windows Form Application as the published ASP.NET application. Prior to Visual Studio 2005, the .NET framework supports the NO-Touch deployment, which allows the Windows Form Application to deploy from a URL or a Unified Name Conversion (UNC) file path, and run in a sandbox in the client, This sandbox has code access security (CAS).
The NO-TOUCH deployment in Visual Studio 2005 has evolved to ClickOnce deployment and some new features have provided Windows Form Program Developers with a bottom structure that is as smooth as deploying a Web application. In particular, Clickonce deployment also provides some support for some improved features, such as program sends, version updates, multi-control, update licenses, update licenses, and design in all structures of Visual Studio. When configuring support. Configuring the pipeline deployment is designed, configuring the ClickonCE deployment by setting various properties of the Publish Property page in the Visual Studio2005's engineering configuration properties. Based on your underlying structure and user group, different deployment resources (file server, web server, or FTP server) have its specific meaning. Clickonce deployment allows you to specify which will be published and installed and installed (for example, install via web pages). It can be configured to determine if the application is installed on the physical drive installed to the client machine. If the client installation is complete, you can specify whether you update check before the program is loaded or run, or how long it is updated, or forced demand updates - is a useful feature for critical update operations. It can also specify the necessary conditions before the installer, the .NET framework itself is like this. And some security settings can be set in the security attribute page. When you will be released, you can generate and publish your application by clicking on the "Project" | "Publishing Project" menu, which generates both the application also released the application. The process of publishing applications is managed by the Publishing Wizard, which mainly views your publishing configuration settings and allows you to change these configurations before publishing. One form last pop-up in the release process lists all the options that need to be determined, and provide an option to determine whether the publisher is also returned to modify settings. The post wizard will then publish the application according to your choice. The deployment program deployment program begins to open the deployment web page on the user and click the hyperlink required to publish this program. The application is linked to a .dePloy file instead of a program that can run. The .Deploy file is one of the two files necessary for the ClickOnce deployment program, which specifies the program deployment and update requirements. The second file is the .manifest file, which specifies the files required for the program run. This is equivalent to the assembly list of the program. .Deploy and .manifest files are deployed by ClickOnce deploying services, System.DeploymentFramework.Service.DeploymentFramework.Service.exe. This service is installed with .NET Framework and requires a .deploy file when the first start is started. It will be required to confirm the download in the form of a dialog, and the user will not see any background operation. After the download is complete, the real application will be loaded to the AppHost.exe program and run it by it. The application is stored in a local cache until you specify that there is no client installation operation. The application starts with the application in the future, and is executed in the local cache until the .debug file specifies a new version in the server. If the application runs in a domain that requires higher configurable security (such as internet or local area network), the ClickOnce deployment program can provide users with program access licenses to the appropriate level to ensure that the program is properly executed. If there is no license program never start, it will not be a chance to run. Clickonce deployment version control and rollback If a program is deployed, an icon will add an icon to the "Start" menu and add an item in the Control Panel | Add Delete program. From the Add Remove program, you can completely uninstall the application or return to the previous version, if there is a previous version.
The version control function of the pipeline deployment program mainly depends on the version number specified by the AssemblyVersion property, the AssemblyVersion property is generated in the AssemblyInfo.cs file, the AssemblyInfo.cs file is generated by each Windows Formwork. Just like this: [Assembly: AssemblyVersion ("1.0. *")] The version number is used to decide whether there is a new version to be used for download. It is also used to name the client temporary folder where the deployment folder and the program are located. The name conversion form of the two folders is the program name _ master number _ subsidiary number _ generation number _ revision number. ClickonCE deployment is a very powerful technology that brought us a lot of benefits, and it could not be described in this article. However, the main motivation deployed using Clickonce is to facilitate the deployment, installation, and control of the version. For more information about it, please refer to the article named "Clickonce: Deploy and Update Your Smart Client Projects Using A Central Server" written by Brian Noyes in this period. Summary When you consider a lot of new features in Visual Studio 2005, you will realize that we just started discussing these you will be used in Windows Forms. These include improved ADO.NET and new object-relational mapping access to relational databases, which uses exhibition new ObjectSpaces technology. The content written here only introduces you the most important new features, and explains the improvement of the productivity of Visual Studio, from the improvement of the integrated development environment and designer to previous versions of the control. Improve (such as text boxes and compound listings) and some new controls (such as GridView and WinBar). GridView and DataContainer controls together with enhanced types of data sets to help you create rich data performance forms and add data to your application faster. Finally, ClickOnce deployed the entire process of deployment of Windows Forms, and provides compatibility with traditional installer. About the author Michael Weinhardt is now updating his new book "C # Windows Form Program Design" with Chris Sells, and writes a column article "Windows Form Probe" for MSDN Online Magazine. Access http://www.mikedub.net Get more information. Chris Sells is an MSDN online magazine content planning, currently the next version of the next version of the Windows operating system (http://msdn.microsoft.com/longhorn). See http://www.selsbrothers.com for more information on Chris and his research results. From the MSDN Magazine's May 2004, this article can be obtained through local newsstands, or its best is to subscribe to this article. Translation by vckbase MTT team