After completing this topic, you should be able to import IDE settings, add a code snippet, and perform some new Windows Forms creation tasks in Visual Studio 2005, given a scenario.
In this exercise, you're required to manage Visual Studio 2005 Integrated Development Environment (IDE) settings, use Windows Forms controls, insert a code snippet in code, and use the BackgroundWorker class.
This involves the following tasks:
BackgroundWorkerSuppose you want to restore an exported version of Visual Studio 2005 IDE settings for a new application.
To import IDE settings, you first need to launch the Import and Export Settings Wizard and specify what you want to use it to do.
How do you launch the wizard and specify that you want to import settings?
Options:
To launch the Import and Export Settings Wizard and specify that you want to import settings, you select Tools - Import and Export Settings and then select the Import selected environment settings radio button.
Alternatively, to launch the wizard, you press Alt+T, I.
You've specified that you want to import IDE settings, and now need to save your existing IDE settings and complete the import process.
How do you complete the steps to import IDE settings from the file named Exported-2006-04-06.vssettings?
Options:
To import the IDE settings from the Exported-2006-04-06.vssettings file, you click Next, accept the default selection of the Yes, save my current settings radio button, click Next, select Exported-2006-04-06.vssettings, and click Finish.
Once you've imported required IDE settings, you need to begin designing a form.
You decide to add a MenuStrip control to the form using the Toolbox.
How do you open the Toolbox and add the control to the form?
Options:
To open the Toolbox and add a MenuStrip control to the form, you select View - Toolbox and double-click MenuStrip.
The form requires standard menu items.
How do you add standard items to the MenuStrip control?
Options:
To add the standard items to the control, you click the arrow in the top right corner of the control and click Insert Standard Items.
You decide to add a ToolStripContainer control to the form, and to disable its left and right panels.
How do you do this?
Options:
To add the ToolStripContainer control and disable its left and right panels, you double-click ToolStripContainer in the Toolbox, and deselect the Left and Right checkboxes.
Suppose you're creating a loan payment calculator form. You've placed a button labeled "Calculate" on the form. Now you need to add the code snippet that calculates the payment to the ButtonClick method.
Suppose you want to use the code snippet named "if", which is located in the Visual C# category of code snippets. To do this, you first need to check the code shortcut you must use to insert the snippet.
How do you locate and select the required code snippet to determine its code shortcut?
Options:
To locate and select the required code snippet, you select Tools - Code Snippets Manager, expand the Visual C# node, and select if.
You've determined that the shortcut for the required code snippet is if. You now need to add the code snippet to your code.
How do you add the code snippet to private void Button1_Click?
Options:
To add the code snippet, you type if in the code inside private void Button1_Click and press the Tab key.
You now need to use the BackgroundWorker class to perform multithreading in your application. You decide to do all the coding without using IntelliSense menus.
Suppose you want to use the BackgroundWorker class to execute the process of iterating through a dictionary.
Complete the code to initialize the object worker as a new instance of the BackgroundWorker class.
using System.ComponentModel;
public class Form1
{
private BackgroundWorker worker;
private void Form1_Load(object sender, System.EventArgs e)
{
worker = MISSING CODE;
worker.WorkerReportsProgress = true;
}
}
The complete code to initialize the object worker as a new instance of the BackgroundWorker class is
worker = new BackgroundWorker();
Next you need to ensure that the BackgroundWorker class produces progress reports for the background process.
Complete the code to do this.
using System.ComponentModel;
public class Form1
{
private BackgroundWorker worker;
private void Form1_Load(object sender, System.EventArgs e)
{
worker = new BackgroundWorker();
worker.MISSING CODE;
worker.DoWork += new DoWorkEventHandler(OnWork);
worker.ProgressChanged += new ProgressChangedEventHandler(OnProgressChanged);
}
}
The complete code to produce progress reports is
WorkerReportsProgress = True;
Last, you need to assign the process to the BackgroundWorker class.
Complete the code to perform the RunWorkerAsync method on the variable worker.
private delegate void ChangeProgressBarHandler(int percentage);
private void ChangeProgressBar(int percentage)
{
ProgressBar1.Value = percentage;
}
private void Button1_Click(object sender, System.EventArgs e)
{
MISSING CODE;
}
The complete code to perform the RunWorkerAsync method on the variable worker is
worker.RunWorkerAsync();
IDE settings have now been restored, Windows Forms controls have been added to a form, and a code snippet has been added to a method. The BackgroundWorker class has also been used in code.
| Top of page |
| Task 1: Importing IDE settings |
| Task 2: Adding Windows Forms controls |
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.