After completing this topic, you should be able to identify various Windows Forms enhancements in Visual Studio 2005.
Visual Studio 2005 provides new Windows Forms controls that simplify form design and extend the functionality of forms.
You can upgrade C# 1.0 or 1.1 projects to C# 2.0 (C# 2005) using the new Upgrade Wizard.
The Upgrade Wizard upgrades some ActiveX controls in the Windows Common Controls Library to Windows Forms controls. However, the differences in functionality between the ActiveX controls and the Windows Forms controls are minimal.
To upgrade Microsoft HTML Object Library controls, however, you use the new managed HTML Document Object Model.
Using the Upgrade Wizard, you can also upgrade the coding language features of an application. For example, the wizard upgrades certain old code to C# 2.0.
To add a Windows Forms control to a form, you first open the Toolbox by selecting View - Toolbox. You can then select a control in the Toolbox and drag it onto the form, or double-click a control to add it to a default position on the form.
Most Windows Forms controls have associated Tasks menus, which enable you to customize the controls. You access the Tasks menu for a control by clicking the control on the form and then clicking the arrow that displays in the control's top right corner.
Several new types of controls in Visual Studio 2005 that simplify form design and enhance form functionality include
MenuStrip
Tasks menu, for example, enables you to add the MenuStrip
control to the ToolStripContainer
control, to insert standard items, and to configure rendering, docking, and the display of grips for the control. Clicking the Edit Items link opens the Items Collection Editor, which you can use to add or remove MenuStrip
components.StatusStrip
control provides a drop-down list of control types that you can embed in it.ToolStrip
control provides a drop-down list of controls that you can add to it. Alternatively, you can add controls to it using the Insert Standard Items link in the Tasks menu for the control.MenuStrip
, StatusStrip
, and ToolStrip
controls at any place on a form by embedding them in the ToolStripContainer
, and then using the Tasks menu for ToolStripContainer
to specify where panels must display.TableLayoutPanel
control lets you create panels that resize easily, using new ColumnSpan
and RowSpan
properties, which mimic those of HTML table cells.FlowLayoutPanel
control allows form content to flow freely as it resizes.TreeView
and ListView
.TreeView
control has a collection of child nodes reserved for every node that it contains.ListView
control now provides a tile view, which displays tiles with icons and text. It also lets you group items into related categories.ImageList
control to display in a ListView
control. The ImageList
control lets you select the image size and bit depth that images will display in, and to select images.BindingNavigator
, BindingSource
, and DataGridView
controls.BindingNavigator
control belongs to the ToolStrip
class, and has buttons for adding, deleting, and navigating data records.BindingSource
control is a back-end control that binds controls on a form to data sources such as Access or SQL databases. You use and manipulate the control programmatically.DataGridView
control displays data in a table. It can show read-only previews of small amounts of data, or large writeable datasets. It can be bound to external source data, or you can add data to it directly.DataGridView
control is similar to the DataGrid
control, but doesn't require that you write your own code. It also supports bound or unbound columns.PropertyGrid
control lets you customize the settings that users can change in an application. You can add customized and expandable property lists. The PropertyGrid
control does not have an associated Tasks menu – you customize it using code and its properties.RichTextBox
and MaskedTextBox
controls.RichTextBox
control makes text entry, display, and formatting easier. To place text in the control, you can enter it directly, or load it in rich (.rtf) or plain (.txt) text format. LoadFile
and SaveFile
. Find
lets you search for text characters or strings. URL links can be displayed correctly using DetectURLs
.MaskedTextBox
control provides enhanced mask characters. Clicking the Set mask link in the control's Tasks menu opens the Input Mask dialog box.SerialPort
control, which uses the new SerialPort
class, enables serial devices such as modems to communicate with an application.MSComm
, and increases digital access to the .NET environment. It is a back-end control without a visual interface.SoundPlayer
control enables you to obtain or specify the file path or URL of a .wav file to load. You attach the code for the soundplayer to an object on the form because it doesn't have a visual interface.WebBrowser
control enables you to incorporate a web browser in a form. The control exposes more application programming interface (API) members than previous versions of C#, and introduces support for client-side scripts.WebBrowser
control. Examples of these properties includeIsWebBrowserContextMenuEnabled
property. This property is set to True by default.WebBrowserShortcutsEnabled
property. This property is set to True by default.AllowNavigation
property, which is set to True by default.AllowWebBrowserDrop
property to False. Its default value is True.Url
property and the Navigate
method. The Url
property isn't set to a default value.What does the PropertyGrid
control enable you to do?
Options:
The PropertyGrid
control enables you to specify which settings a user can change in an application.
Option 1 is incorrect. The Application Property tabbed page provides access to the Application Framework properties for an application.
Option 2 is incorrect. Every control has its own properties, which you access by right-clicking the control and selecting Properties.
Option 3 is incorrect. The DataGridView
control properties enable you to change how data is displayed in an application.
Option 4 is correct. The PropertyGrid
control provides customizable and expandable property lists that enable users to change application settings.
What can you do using the WebBrowser
control?
Options:
The WebBrowser
control enables you to configure a control to navigate to a specific location, and to prevent users from navigating away from a page.
Option 1 is incorrect. The user only sees the result of your actions with WebBrowser
, which integrates Internet Explorer into applications.
Option 2 is correct. You can configure a control to navigate to an address using the Url
property and the Navigate
method.
Option 3 is incorrect. The WebBrowser
control provides greater access to API members than previous versions of Visual Studio, but it does not create them.
Option 4 is correct. You can prevent a user navigating away from a page using the AllowNavigation
property, which employs the Navigating
and Navigated
event handlers.
The BackgroundWorker
control is from a new class that overcomes slow interface responses by executing operations asynchronously, on a thread other than the one your program uses.BackgroundWorker
is a class for back-end control – there is no direct visual link to it, so it must be used programmatically.
When you write code in Visual Studio 2005, IntelliSense provides numerous pop-up windows that provide for the optional insertion of end constructs.
You can disable this feature by modifying Visual Studio 2005 settings.
There are three main components to BackgroundWorker
. First you declare and create a variable to serve as an instance of the BackgroundWorker
control.
Then you create the methods which cause the process to run on a background thread, as well as the code for the process itself.
Finally, you provide the code that causes the process to be executed by BackgroundWorker
.
To code BackgroundWorker
, you first declare and instantiate a variable in the subroutine for the form Load
event. This example does not use IntelliSense code completion.
using System.ComponentModel;
public class Form1
{
private BackgroundWorker worker;
private void Form1_Load(object sender, System.EventArgs e)
{
worker = new BackgroundWorker();
You then enable the WorkerReportsProgress
property by assigning it the value of True. This causes the BackgroundWorker
to report its progress.
worker.WorkerReportsProgress = True;
You add the event handler that will trigger when the DoWork
event of BackgroundProcess
occurs. This event will occur when methods class methods such as RunWorkerAsync
run. In this example, the user-defined OnWork
method is passed to the handler so it will execute when the handler is triggered.
using System.ComponentModel;
public class Form1
{
private BackgroundWorker worker;
private void Form1_Load(object sender, System.EventArgs e)
{
worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += new DoWorkEventHandler(OnWork);
You then add the event handler for the ProcessChanged
event, which is raised by the class's ReportProgress
method. This event is intended to check the progress of the background progress and in this case, the user-defined OnProgressChanged
method is passed to the handler for execution. This will conclude the Form_Load
event.
worker.ProgressChanged += new ProgressChangedEventHandler(OnProgressChanged);
Next you define the subroutine for the OnWork
method. In this subroutine, you create the process that you want to run on a background thread.
}
}
private void OnWork(object sender, DoWorkEventArgs e)
{
int I;
for (I = 1; I <= 100; I++) {
System.Threading.Thread.Sleep(10);
worker.ReportProgress(I);
}
}
You define the OnProcessChanged
method. This will run the Invoke
method, passing a new handler for a progress bar and will run its own customized method for that handler, all designed to display the percentage of the progress that has been completed.
Finally, you directly define the handler for a form button's (button1) click event. This event will run the RunWorkerAsync
method to begin the entire example.
Suppose you need to use the BackgroundWorker
class to run a background process when the user clicks a button.
Complete the code that adds the handler that begins the process for a BackgroundWorker
to an object named worker
.
MISSING CODE += new DoWorkEventHandler(OnWork);
You complete the code that adds the DoWork
handler to the worker
object by typing
worker.DoWork
You've declared and instantiated the variable worker
as an instance of BackgroundWorker
.
Complete the code that causes BackgroundWorker
to run when the user clicks a button.
private void Button1_Click(object sender, System.EventArgs e)
{
MISSING CODE;
}
The code that causes BackgroundWorker
to run when the user clicks a button is
worker.RunWorkerAsync()
Visual Studio 2005 lets you configure Application Framework settings using the Application pane of the properties window for an application.
You can enable or disable Windows XP visual styles, using the Enable XP visual styles checkbox.
You can specify whether the application is single-instance by selecting the Make single instance application checkbox. This is possible because Visual Studio uses the new MyProject namespace.
You can determine whether an application's settings are saved when it closes, by selecting the Save My.Settings on Shutdown checkbox.
You can determine the application's authentication mode – Windows or Application-Defined – using the Authentication mode drop-down list box. You can also set the event that triggers application shutdown, and configure the application's splash screen.
The Debug properties pane now enables you to activate a new hosting process. You do this by selecting the new Enable the Visual Studio hosting process checkbox.
Which of these options are treated as Application Framework settings?
Options:
Determining the application's authentication mode and enabling XP visual styles are Application Framework settings.
Option 1 is correct. The Application Framework settings determine how an application functions once it is compiled.
Option 2 is correct. The Application Framework settings enable you to customize the application interfaces.
Option 3 is incorrect. The SerialPort control determines how devices can communicate with your application.
Option 4 is incorrect. The Upgrade Wizard automatically upgrades any coding language features that can be upgraded.
Visual Studio 2005 includes several new Windows Forms controls that simplify and enhance form design. You access these controls in the Visual Studio Toolbox.
The new BackgroundWorker
control makes it easy to assign processes to background threads. The Application pane of the properties window now lets you configure Application Framework settings directly.
Copyright © 2006 SkillSoft. All rights reserved.
SkillSoft and the SkillSoft logo are trademarks or registered trademarks
of SkillSoft in the United States and certain other countries.
All other logos or trademarks are the property of their respective owners.