- •brief contents
- •about this book
- •The Windows Forms namespace
- •Part 1: Hello Windows Forms
- •Part 2: Basic Windows Forms
- •Part 3: Advanced Windows Forms
- •Who should read this book?
- •Conventions
- •Action
- •Result
- •Source code downloads
- •Author online
- •acknowledgments
- •about .NET
- •Casting the .NET
- •Windows Forms overview
- •about the cover illustration
- •Hello Windows Forms
- •1.1 Programming in C#
- •1.1.1 Namespaces and classes
- •1.1.2 Constructors and methods
- •1.1.3 C# types
- •1.1.4 The entry point
- •1.1.5 The Application class
- •1.1.6 Program execution
- •1.2 Adding controls
- •1.2.1 Shortcuts and fully qualified names
- •1.2.2 Fields and properties
- •1.2.3 The Controls property
- •1.3 Loading files
- •1.3.1 Events
- •1.3.2 The OpenFileDialog class
- •1.3.3 Bitmap images
- •1.4 Resizing forms
- •1.4.1 Desktop layout properties
- •1.4.2 The Anchor property
- •1.4.3 The Dock property
- •1.5 Recap
- •2.1 Programming with Visual Studio .NET
- •2.1.1 Creating a project
- •Action
- •Result
- •2.1.2 Executing a program
- •Action
- •Result
- •2.1.3 Viewing the source code
- •View the code generated by Visual Studio .NET
- •Action
- •Result
- •2.2 Adding controls
- •2.2.1 The AssemblyInfo file
- •Action
- •Results
- •2.2.2 Renaming a form
- •Action
- •Result
- •2.2.3 The Toolbox window
- •Action
- •Result
- •2.3 Loading files
- •2.3.1 Event handlers in Visual Studio .NET
- •Action
- •Result
- •2.3.2 Exception handling
- •Action
- •Result
- •Action
- •Results and Comments
- •2.4 Resizing forms
- •2.4.1 Assign the Anchor property
- •Action
- •Result
- •2.4.2 Assign the MinimumSize property
- •Action
- •Result
- •2.5 Recap
- •Basic Windows Forms
- •Menus
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •3.3 Click events
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •3.5 Context menus
- •Action
- •Result
- •Action
- •Result
- •3.6 Recap
- •Status bars
- •4.1 The Control class
- •4.2 The StatusBar class
- •Action
- •Result
- •Action
- •Result
- •4.3.1 Adding panels to a status bar
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •4.5 Recap
- •Reusable libraries
- •5.1 C# classes and interfaces
- •5.2 Class libraries
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •5.3 Interfaces revisited
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •5.4 Robustness issues
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Common file dialogs
- •Action
- •Results
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •6.3 Paint events
- •Action
- •Result
- •Action
- •Result
- •6.4 Context menus revisited
- •Action
- •Result
- •Action
- •Result
- •6.5 Files and paths
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •6.6 Save file dialogs
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •6.7 Open file dialogs
- •Action
- •Result
- •Action
- •Result
- •6.8 Recap
- •Drawing and scrolling
- •7.1 Form class hierarchy
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •7.4 Panels
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Dialog boxes
- •8.1 Message boxes
- •Action
- •Result
- •Action
- •Result
- •8.1.4 Creating A YesNoCancel dialog
- •Action
- •Result
- •Action
- •Result
- •8.2 The Form.Close method
- •8.2.1 The relationship between Close and Dispose
- •Action
- •Result
- •8.3 Modal dialog boxes
- •Action
- •Result
- •Action
- •Result
- •8.3.2 Preserving caption values
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Basic controls
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •9.1.2 Creating a derived form
- •Action
- •Result
- •9.2 Labels and text boxes
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •9.3.6 Adding AlbumEditDlg to our main form
- •Action
- •Result
- •Action
- •Result
- •9.4 Recap
- •List controls
- •10.1 List boxes
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •10.2 Multiselection list boxes
- •10.2.1 Enabling multiple selection
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •10.3 Combo boxes
- •Action
- •Result
- •Action
- •Result
- •10.4 Combo box edits
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •10.5 Owner-drawn lists
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •More controls
- •Action
- •Result
- •Action
- •Result
- •11.2 Tab pages
- •Action
- •Result
- •Action
- •Result
- •11.3.1 Dates and times
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •11.5 Recap
- •A .NET assortment
- •12.1 Keyboard events
- •Action
- •Result
- •Action
- •Result
- •12.2 Mouse events
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •12.3 Image buttons
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •12.4 Icons
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •12.5 Recap
- •Toolbars and tips
- •13.1 Toolbars
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •13.4.2 Creating tool tips
- •Action
- •Result
- •Action
- •Result
- •Advanced Windows Forms
- •List views
- •14.2 The ListView class
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •14.2.3 Populating a ListView
- •Action
- •Result
- •Action
- •14.3 ListView columns
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •14.6 Recap
- •Tree views
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •15.3 Dynamic tree nodes
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •15.4 Node selection
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •15.5 Fun with tree views
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Multiple document interfaces
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •16.3 Merged menus
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •16.4 MDI children
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •16.5 MDI child window management
- •Action
- •Result
- •Action
- •Result
- •16.6 Recap
- •Data binding
- •17.1 Data grids
- •Action
- •Result
- •Action
- •Result
- •17.2 Data grid customization
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Odds and ends .NET
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •18.2 Timers
- •Action
- •Result
- •Action
- •Result
- •18.3 Drag and drop
- •Action
- •Result
- •Action
- •Result
- •18.4 ActiveX controls
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •Action
- •Result
- •18.5 Recap
- •C# primer
- •A.1 C# programs
- •A.1.1 Assemblies
- •A.1.2 Namespaces
- •A.2 Types
- •A.2.1 Classes
- •A.2.2 Structures
- •A.2.3 Interfaces
- •A.2.4 Enumerations
- •A.2.5 Delegates
- •A.3 Language elements
- •A.3.1 Built-in types
- •A.3.2 Operators
- •A.3.3 Keywords
- •A.4 Special features
- •A.4.1 Exceptions
- •A.4.2 Arrays
- •A.4.3 Main
- •A.4.4 Boxing
- •A.4.5 Documentation
- •.NET namespaces
- •B.1 System.Collections
- •B.2 System.ComponentModel
- •B.3 System.Data
- •B.4 System.Drawing
- •B.5 System.Globalization
- •B.6 System.IO
- •B.7 System.Net
- •B.8 System.Reflection
- •B.9 System.Resources
- •B.10 System.Security
- •B.11 System.Threading
- •B.12 System.Web
- •B.13 System.Windows.Forms
- •B.14 System.XML
- •Visual index
- •C.1 Objects
- •C.2 Marshal by reference objects
- •C.3 Components
- •C.4 Common dialogs
- •C.7 Event data
- •C.8 Enumerations
- •For more information
- •bibliography
- •Symbols
- •Index
|
|
|
|
|
|
CREATE MENU IN PARENT FORM |
||
|
|
|
|
|
|
|
|
|
|
|
|
|
Action |
|
|
Result |
|
|
|
|
|
|
|
|
||
7 |
In the ParentForm.cs [Design] |
|
||||||
|
window, add a new top-level |
|
||||||
|
Help menu. |
|
|
|
|
|
||
|
|
|
Settings |
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
Property |
|
|
Value |
|
||
|
|
(Name) |
|
menuHelp |
|
|||
|
|
MergeOrder |
|
9 |
|
|
||
|
|
Text |
|
|
&Help |
|
||
|
|
|
|
|
|
|
|
|
8 |
Add a single About MyPhotos |
|
||||||
|
menu item under this new |
|
||||||
|
menu. |
|
|
|
|
|
||
|
|
|
Settings |
|
|
|
||
|
|
|
|
|
|
|
||
|
|
Property |
|
|
Value |
|
||
|
|
(Name) |
|
|
menuAbout |
|
||
|
|
Text |
|
&About MyPhotos… |
|
|||
|
|
|
|
|
|
|
|
|
Our design is ready to go. Our next topic is the generation of wrapper classes for ActiveX controls.
18.4.2WRAPPING THE WEB BROWSER CONTROL
As we mentioned earlier, the .NET Framework provides a tool for creating a derived AxHost class from an existing ActiveX control. This section will use this tool to wrap the standard browser control for use in our application.
The Windows Forms ActiveX Control Importer program is called “aximp” and is available as part of the Visual Studio .NET product. This program is run on the command line and accepts an ActiveX control library.
C:\> aximp source-file
The source-file here is the DLL or OCX file containing the ActiveX control. For our purposes, the Web Browser control is located in the file shdocvw.dll in the Windows “system32” directory. An AxHost based class can be created with the following steps:
ACTIVEX CONTROLS |
629 |
CREATE WRAPPER CLASS FOR WEB BROWSER CONTROL
|
Action |
Result |
|
|
|
1 |
Display a Visual Studio .NET |
|
|
Command Prompt. |
|
|
How-to |
|
|
This is available from the Start |
|
|
menu in the Microsoft Visual |
|
|
Studio .NET folder, under the |
|
|
Visual Studio .NET Tools heading. |
|
|
|
|
2 |
Create a suitable directory for |
|
|
holding the generated wrapper |
|
|
class. |
|
|
cd Windows Forms\Projects |
|
|
mkdir WebBrowser |
|
|
Note: This example uses the |
|
|
directory “C:\Windows |
|
|
Forms\Projects\WebBrowser” for |
|
|
this purpose. You should use an |
|
|
appropriate directory for your |
|
|
application. |
|
|
|
|
3 |
Change the current directory to be |
|
|
this new directory. |
|
|
cd WebBrowser |
|
|
|
|
4 |
Generate the wrapper class by |
Two new assemblies are generated in the current |
|
executing the following command: |
directory. These are: |
|
aximp |
aximp c:\winnt\ |
|
c:\winnt\system32\shdocvw.dll |
system32\shdocvw.dll |
|
Note: Depending on your operat- |
|
|
ing system, you may need to |
|
|
replace “c:\winnt” in this com- |
|
|
mand with the appropriate Win- |
|
|
dows directory. |
|
|
|
|
The two generated files work together to present the ActiveX control as a Windows Forms control in the .NET environment. The first file AxShDocVw.dll, is named by prepending “Ax” to the given source file name. This file encapsulates the Windows Forms proxy class for the control, derived from the AxHost class. Each object from the original library is defined under a namespace identical to the assembly name, in this case the AxShDocVw namespace.
The second file ShDocVw.dll, named identical to the given source file name, contains the common language runtime proxy for the COM types from the source library. This file is used implicitly by the Windows Forms control defined in the first file.
With a wrapper for our Web Browser control defined, we are ready to implement the internals of our About box.
630 |
CHAPTER 18 ODDS AND ENDS .NET |
18.4.3USING THE WEB BROWSER CONTROL
So far we have defined a user interface and created a wrapper class for the Web Browser ActiveX control. In this section we will implement the AboutBox form to work as described earlier.
The following table begins this process by describing the changes required for our standard Windows Forms controls.
HANDLE THE STANDARD CONTROLS
|
Action |
Result |
|
|
|
1 |
In the AboutBox.cs code window, |
protected const int SDI_ICON = 0; |
|
create two constants for the two |
protected const int MDI_ICON = 1; |
|
types of icons in our image list. |
|
|
|
|
2 |
Implement an IsMdiApplication |
public bool IsMdiApplication |
|
property to define whether the |
{ |
|
active form is a MDI application. |
get { return (lblIcon.ImageIndex |
|
== MDI_ICON); } |
|
|
|
|
|
How-to |
set |
|
a. In the get accessor, return |
{ |
|
if (value) |
|
|
whether the current image index |
|
|
lblIcon.ImageIndex = MDI_ICON; |
|
|
in the lblIcon control is the |
else |
|
MDI icon. |
lblIcon.ImageIndex = SDI_ICON; |
|
b. In the set accessor, assign the |
} |
|
} |
|
|
ImageIndex for the lblIcon |
|
|
control based on the assigned |
|
|
value setting. |
|
|
|
|
3 |
Implement an AboutText property |
public string AboutText |
|
to get or set the Text property for |
{ |
|
the lblAboutText control. |
get { return lblAboutText.Text; } |
|
set { lblAboutText.Text = value; } |
|
|
|
|
|
|
} |
|
|
|
4 |
In the ParentForm class, add a |
private void menuAbout_Click |
|
Click handler for the About |
(object sender, System.EventArgs e) |
|
MyPhotos menu to create an |
{ |
|
AboutBox dlg = new AboutBox(); |
|
|
AboutBox instance and assign its |
|
|
dlg.IsMdiApplication = true; |
|
|
settings. |
Version ver = new |
|
How-to |
|
|
Version(Application.ProductVersion); |
|
|
a. Set IsMdiApplication to |
dlg.AboutText |
|
true. |
= String.Format("MyPhotos (MDI) " |
|
b. Set the AboutText property to |
+ "Application, Version {0:#}.{1:#} " |
|
+ "\nSample for /"Windows Forms " |
|
|
an appropriate string. |
+ "Programming with C#\"\nby " |
|
c. Set the Owner property to the |
+ "Erik Brown \nCopyright (C) 2001 " |
|
+ "Manning Publications Co.", |
|
|
current Form. |
|
|
ver.Major, ver.Minor); |
|
|
d. Set the dialog’s Icon to use the |
dlg.Owner = this; |
|
current form’s icon. |
dlg.Icon = this.Icon; |
|
|
|
|
e. Show the dialog. |
dlg.Show(); |
|
|
} |
|
|
|
ACTIVEX CONTROLS |
631 |
HANDLE THE STANDARD CONTROLS (continued)
|
Action |
Result |
|
|
|
5 |
Back in the AboutBox class, add a |
private void linkClose_LinkClicked |
|
LinkClicked handler for the |
(object sender, System.Windows.Forms. |
|
linkClose link label control to |
LinkLabelLinkClickedEventArgs e) |
|
{ |
|
|
close the form. |
|
|
Close(); |
|
|
How-to |
} |
|
|
|
|
This is the default event for link |
|
|
labels, so simply double-click the |
|
|
link control in the design window. |
|
|
|
|
These changes configure the controls with the appropriate information and behavior. Note that the LinkClicked event handler receives a LinkLabelLinkClickedEventArgs object as its event parameter. The LinkLabel class provides a Links property that defines one or more links, as a collection of LinkLabel.Link objects, within the single link label control. The LinkLabelLinkClickedEventArgs object specifies the link that was clicked by the user.
In our application, our labels use the entire text string as a link. Let’s continue the previous steps and handle the linkWebSite control to see how to bring up a Web Browser.
|
HANDLE THE LINKWEBSITE CONTROL |
|
|
|
|
|
Action |
Result |
|
|
|
6 |
Add a reference to the |
|
|
generated AxSHDocVW.dll |
|
|
assemply in the MyPhotos |
|
|
project. |
|
|
How-to |
|
|
In the Add Reference dialog, |
|
|
click the Browse... button to |
|
|
locate and select the |
|
|
generated assembly. |
|
|
|
|
7 |
In the AboutBox.cs code |
using AxSHDocVw; |
|
window, indicate that we will |
|
|
use this library in our code. |
|
|
|
|
632 |
CHAPTER 18 ODDS AND ENDS .NET |
HANDLE THE LINKWEBSITE CONTROL (continued)
|
Action |
Result |
|
|
|
8 |
Define the following fields in |
private AxWebBrowser browser; |
|
our AboutBox class: |
private const string startPage |
|
a. A browser field representing |
= "www.manning.com/eebrown"; |
|
|
|
|
a WebBrowser control. |
Note: The AxWebBrowser class here is based on |
|
b. A constant string contain- |
|
|
Microsoft’s SHDocVw.dll library from the Windows |
|
|
ing the web site we will dis- |
directory. We will not cover the contents of this |
|
play. |
library in detail, as it is beyond the scope of our cur- |
|
|
rent discussion. Look up the WebBrowser Control |
|
|
index entry in the online documentation provided |
|
|
with Visual Studio .NET for more information on this |
|
|
class. |
|
|
|
9 |
Add a LinkLabel event |
private void linkWebSite_LinkClicked |
|
handler for the linkWebSite |
(object sender, System.Windows.Forms. |
|
control. |
LinkLabelLinkClickedEventArgs e) |
|
{ |
|
|
|
|
|
|
|
10 |
If the browser control already |
if (browser != null) |
|
exists, then shut down the |
{ |
|
web site and hide the Panel |
// Shut down existing browser |
|
pnlWebSite.Visible = false; |
|
|
object. |
|
|
browser.Dispose(); |
|
|
Note: This code resets the |
browser = null; |
|
|
|
|
dialog to its original state. |
// Reset dialog settings |
|
|
linkWebSite.Text |
|
|
= "Click for book's web site"; |
|
|
this.Size = new Size(400, 140); |
|
|
this.Text = "About MyPhotos"; |
|
|
} |
|
|
|
11 |
If the browser control does not |
else |
|
exist, then create the browser |
{ |
|
and define some initial |
// Create web browser object |
|
browser = new AxWebBrowser(); |
|
|
settings. |
|
|
browser.Dock = DockStyle.Fill; |
|
|
How-to |
browser.TitleChange += new |
|
a. Create a new AxWeb- |
|
|
DWebBrowserEvents2_TitleChangeEventHandler |
|
|
Browser control. |
(this.browser_TitleChange); |
|
b. Set its Dock property to |
browser.HandleCreated += new |
|
EventHandler(this.browser_HandleCreated); |
|
|
Fill. |
|
|
|
|
|
c. Add a TitleChange event |
Note: The HandleCreated event is inherited from |
|
handler. |
|
|
the Control class and uses the familiar mechanism. |
|
|
d. Add a HandleCreated |
|
|
The TitleChange event is part of the WebBrowser |
|
|
event handler. |
control, and is part of the AxSHDocVw namespace. |
|
|
Details on the DWebBrowserEvents2 interface |
|
|
and the TitleChange event are included with the |
|
|
online documentation for Visual Studio .NET. |
|
|
|
12 |
Make the Panel control on the |
// Show panel containing new browser |
|
form visible and add the |
pnlWebSite.SuspendLayout(); |
|
browser control to appear |
pnlWebSite.Visible = true; |
|
pnlWebSite.Controls.Add(browser); |
|
|
within this panel. |
|
|
pnlWebSite.ResumeLayout(); |
|
|
|
|
ACTIVEX CONTROLS |
633 |
HANDLE THE LINKWEBSITE CONTROL (continued)
|
Action |
Result |
|
|
|
13 |
Modify the text displayed for |
linkWebSite.Text = "Click to hide web page"; |
|
the linkWebSite control and |
this.Size = new Size(600, 400); |
|
enlarge the Form to be |
} |
|
} |
|
|
600x400 pixels. |
|
|
|
|
|
|
|
14 |
Create the handler for the |
private void browser_TitleChange |
|
TitleChange event to display |
(object sender, |
|
the new document title in the |
DWebBrowserEvents2_TitleChangeEvent e) |
|
{ |
|
|
title bar of the AboutBox form. |
|
|
this.Text = e.text; |
|
|
|
} |
|
|
|
15 |
Add a DisplayPage method |
protected void DisplayPage(string url) |
|
to navigate to a given URL. |
{ |
|
How-to |
// These are required because the importer |
|
// assumes these are in/out parameters |
|
|
a. Create object instances to |
// and defines them as passed by reference. |
|
represent the reference |
object param2 = 0; |
|
object param3 = ""; |
|
|
parameters. |
|
|
object param4 = ""; |
|
|
b. Display the wait cursor. |
object param5 = ""; |
|
c. Use the Navigate method |
try |
|
to display the given URL. |
{ |
|
d. Finally, reset the current |
Cursor.Current = Cursors.WaitCursor; |
|
browser.Navigate(url, |
|
|
cursor. |
|
|
ref param2, ref param3, |
|
|
Note: The Navigate method |
ref param4, ref param5); |
|
is discussed in the online doc- |
} |
|
finally |
|
|
umentation. |
|
|
{ |
|
|
The four param objects are |
Cursor.Current = Cursors.Default; |
|
required here to match the |
} |
|
signature of the Navigate |
} |
|
|
|
|
method as defined by the |
|
|
ActiveX Control Importer |
|
|
(aximp.exe). A future version |
|
|
of the importer may permit |
|
|
these settings to be null. |
|
|
|
|
16 |
Create the handler for the |
public void browser_HandleCreated |
|
HandleCreated event to |
(object sender, EventArgs evArgs) |
|
display the start page. |
{ |
|
// The WebBrowser has been created |
|
|
|
|
|
How-to |
// Display the starting page |
|
a. Display the starting page |
DisplayPage(startPage); |
|
|
|
|
using the DisplayPage |
// Remove this handler |
|
method. |
browser.HandleCreated -= new |
|
b. Remove the Handle- |
EventHandler(this.browser_HandleCreated); |
|
} |
|
|
Created handler. |
|
|
|
|
|
|
|
This completes our implementation. Compile and run to view the AboutBox dialog in all its glory. You will notice that when viewing the web page within our application, the user cannot navigate to an arbitrary web address. This is very different than
634 |
CHAPTER 18 ODDS AND ENDS .NET |