asp:Feature
LANGUAGES: ALL
ASP.NET
VERSIONS: 2.0
What s New in Windows Forms 2.0: Part II
New Deployment Technology and Windows Controls
By Wei-Meng Lee
This article continues our journey into discovering what
is new in Windows Forms 2.0. In this second installment, we ll look at the new
deployment technology known as ClickOnce. I will also discuss a new feature
known as RegFree COM and how it can be used together with ClickOnce to simplify
your deployment task. I ll end the article with a look at some new and improved
Windows controls and how you can use them to create professional Office-like
applications.
ClickOnce
One of the major challenges faced by application
developers is how to handle the complexities of deploying and updating Windows
applications on customers machines, which often have different hardware and
software configurations. Over the last few years, developers have been moving
to Web applications so that applications can be accessed ubiquitously via a Web
browser. However, Web applications are considerably much more difficult to
build than Windows applications, and don make full use of the rich
functionalities accorded by the Windows operating system.
In Visual Studio 2005, Microsoft introduced the new
ClickOnce deployment technology. Using ClickOnce, applications can be installed
via Web servers and run with minimal user interaction. Moreover, an application
deployed using ClickOnce can be configured to update itself automatically.
ClickOnce deployment allows non-administrative users to
install apps, and grants only those Code Access Security permissions necessary
for the application. As a developer, you can fine-tune the security settings
needed for the application. A detailed look at this topic is beyond the scope
of this article. For more information, check out http://msdn2.microsoft.com/en-us/library/83b10s12.aspx.
Using ClickOnce, let s deploy the application we built in Part
I. First, publish the application by going to Build | Publish WinForms 2.0
(see Figure 1).
Figure 1: Publishing an application.
You will be asked to specify the location to publish the
application (see Figure 2). You can deploy the application using: disk, file
share, FTP, or HTTP. For this example, use the default URL (HTTP method;
deployed to the local IIS) and click Next.
Figure 2: Specifying the location to
publish the application.
You can choose if the application will be available only
in online mode, or if it will be available in either online or offline mode
(see Figure 3). Click Next.
Figure 3: Deciding if the
application is available offline.
The application will now be published to the specified
destination. Click Finish to publish the application. A Web page will be shown
(see Figure 4). You can click the Install button to install the application on
your local computer or you can load this page from another computer and install
it on that computer. Note that for ClickOnce to work, the local computer must
already have the .NET Framework 2.0 installed.
Figure 4: A Web page for installing
the application.
When you click the Install button, a security warning is
displayed (see Figure 5). Click Install. This security warning will not appear
if you have configured the security settings of your application.
Figure 5: Security prompt.
The application will now be installed and launched
automatically. You can also launch the application from Start | Programs | <Company
Name>/WinForms2.0.
Suppose we now make some changes to the original
application. Let s add a background image to the form and then republish the
application.
When the installed application is launched from the Start
menu, a check is made to the Web server to see if the application has been
changed. Because the original application has been changed and republished, you ll
see the dialog box shown in Figure 6. To upgrade the application, click OK.
Click Skip if you don t want to upgrade the application. The new application
will now load (see Figure 7).
Figure 6: Detecting an upgrade.
Figure 7: Launching the new
application.
RegFree COM
In Visual Studio 2005, there is a new feature known as
RegFree COM (Registration-Free COM). Using RegFree COM, you can deploy an
application that uses a COM component without needing to register it on the
user s machine, so you avoid the notorious problems of DLL Hell and even
can have multiple versions of the COM component running on the same machine.
RegFree COM works by automatically generating a manifest
from the COM component s type library and component registration on the
developer s machine. Therefore, although it is not required to install the
component on the end-user s machines, a copy must be registered on the
developer s machine.
To use RegFree COM, all COM components referenced in
Visual Studio 2005 have a new Isolated property. If you set Isolated to True,
then the component can be deployed through ClickOnce and Visual Studio 2005
will automatically do all the work to deploy the COM component onto the target
machine (without needing to register it on the target machine).
As an example, let s add a new OCX control to our project.
This control (Knob Control 2.0; see Figure 8) comes with the installation of
the Ahead Nero application. To use this in your application control, add it to
your Toolbox by right-clicking on the Toolbox and then selecting Choose Items.
Figure 8: Using an OCX control.
Add the Knob control to the form (see Figure 9). You ll
use this Knob control to navigate between all the records in the table.
Figure 9: Using the Knob control.
Add the following code in bold to the Form1_Load event to
initialize the Knob control:
Private Sub Form1_Load( _
ByVal sender As
System.Object, _
ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code
loads data into
'the
'NorthwindDataSet.Employees' table.
'You can move, or remove
it, as needed.
Me.EmployeesTableAdapter.Fill(Me.NorthwindDataSet.Employees)
EmployeesBindingSource.Position
= My.Settings.CurrentRecord
AxKnob1.Min = 1
AxKnob1.Max = EmployeesBindingSource.Count
End Sub
When the position in the Knob control is changed, you ll
navigate to the appropriate record:
Private Sub AxKnob1_PositionChanged( _
ByVal sender As
System.Object, _
ByVal e As
AxAUDIOCONTROLS2Lib. _
_DKnobEvents_PositionChangedEvent) _
Handles
AxKnob1.PositionChanged
EmployeesBindingSource.Position = AxKnob1.Position - 1
End Sub
When the records change position, you ll also update the
Knob control:
Private Sub EmployeesBindingSource_CurrentChanged( _
ByVal sender As Object, _
ByVal e As
System.EventArgs) _
Handles
EmployeesBindingSource.CurrentChanged
AxKnob1.Position =
EmployeesBindingSource.Position + 1
End Sub
Under the References section in Solution Explorer (click
on the Show All Files button located second from left at the top of Solution
Explorer), view the properties of AxAuDIOCONTROLS2Lib and set its Isolated
property to True (see Figure 10).
Figure 10: Setting the Isolated
property for RegFree COM.
That s it! You can now deploy the application using
ClickOnce and Visual Studio 2005 will automatically take care of installing the
OCX control on machines that don t have it.
New Controls
Windows Forms 2.0 comes with several new controls. Here
are some of the noteworthy ones (Figure 11 shows the various controls in action):
- MenuStrip.
Provides a menu system for a form.
- ToolStrip.
Provides a container for Windows toolbar objects.
- StatusStrip.
Represents a Windows status bar control.
- ToolStripContainer.
Provides panels on each side of the form and a central panel that can hold one
or more controls.
Figure 11: Using the various new
controls.
Notice that the MenuStrip and ToolStrip controls have a similar
look and feel to those found in Office applications. In fact, in Windows Forms
2.0, you can now create professional-looking applications that mimic those of
Microsoft s. You can also dock the controls in various locations (see Figure 12).
Figure 12: Docking the controls.
The Splitter control available in Windows Forms 1.x is
improved, and is now known as the SplitContainer control (the old Splitter
control is still available for backward compatibility). You can now drag and
drop the SplitContainer control onto the form and it will automatically add
SplitterPanel controls for you to add other controls.
Figure 13 shows that the SplitContainer contains two
SplitterPanel controls with the left panel occupied by the TreeView control and
the right panel occupied by a Button control and a TextBox control.
Figure 13: Using the SplitContainer
control.
Besides the SplitContainer control, some existing controls
are also enhanced. For example, the ComboBox control now supports the new
AutoCompleteMode property. As an example, Figure 14 shows a form populated with
a ComboBox control, a Button control, and a WebBrowser control.
Figure 14: Enhanced and new controls
in Windows Forms 2.0.
In the Properties window for the ComboBox control, you can
set the AutoCompleteSource to one of the choices shown in Figure 15. The table
in Figure 16 shows the description of each AutoCompleteSource. Let s set the
AutoCompleteSource property to AllUrl.
Figure 15: Values in the
AutoCompleteSource property.
|
Member Name
|
Description
|
|
AllSystemSources
|
Specifies the equivalent of FileSystem and AllUrl as the
source. This is the default value when AutoCompleteMode has been set to a
value other than the default.
|
|
AllUrl
|
Specifies the equivalent of HistoryList and
RecentlyUsedList as the source.
|
|
CustomSource
|
Specifies strings from a built-in
AutoCompleteStringCollection as the source.
|
|
FileSystem
|
Specifies the file system as the source.
|
|
FileSystemDirectories
|
Specifies that only directory names and not file names
will be automatically completed.
|
|
HistoryList
|
Includes the Uniform Resource Locators (URLs) in the
history list.
|
|
ListItems
|
Specifies that the items of the ComboBox represent the
source.
|
|
None
|
Specifies that no AutoCompleteSource is currently in
use. This is the default value of AutoCompleteSource.
|
|
RecentlyUsedList
|
Includes the Uniform Resource Locators (URLs) in the
list of those URLs most recently used.
|
Figure 16: AutoCompleteSource
members.
Next, set its AutoCompleteMode to Suggest (see Figure 17).
Figure 17: Values in the
AutoCompleteMode property.
Double-click the Go button and code the following:
Private Sub btnGo_Click( _
ByVal sender As
System.Object, _
ByVal e As
System.EventArgs) _
Handles btnGo.Click
WebBrowser1.Navigate(cbbURL.Text)
End Sub
Essentially, the WebBrowser control will load the Web page
using the URL specified in the ComboBox control.
Press F5 to test the application. Notice that as you type,
the ComboBox control will display a list of matching URLs (based on the sites
you have visited previously; see Figure 18).
Figure 18: Typing in the ComboBox
control.
Figure 19 shows what happens if you were to set the
AutoCompleteMode property to Append. The SuggestAppend mode combines both the
Suggest and the Append modes (see Figure 20).
Figure 19: Using the Append mode.
Figure 20: Using the SuggestAppend
mode.
Conclusion
In this article you have learned how the ClickOnce
deployment technology allows you to deploy and update Windows applications with
ease. And to further simplify deployment, you can use RegFree COM to deploy COM
objects to your clients machine without needing to perform any manual
installation.
In this two-part article series I have shown you some of
the new features in Windows Forms 2.0. Using these new features, you can now
create professional-looking application with ease. If you haven t tried Visual
Studio 2005 yet, now is the time to take it for a spin!
Wei-Meng Lee (http://weimenglee.blogspot.com),
is a technologist and founder of Developer Learning Solutions, a technology
company specializing in hands-on training on the latest Microsoft technologies.
Wei-Meng speaks regularly at international conferences and has authored and co-authored
numerous books on .NET, XML, and wireless technologies, including ASP.NET 2.0: A Developer s Notebook and Visual Basic 2005 Jumpstart (both from O Reilly
Media, Inc).