| By Aaron Brethorst | Article Rating: |
|
| June 29, 2005 04:00 PM EDT | Reads: |
50,641 |
Now we're going to make the dialog consistent with the Visual Studio UI Guidelines. If you're interested in learning more about creating a Visual Studio consistent user experience refer, to the document located in C:\Program Files\VSIP 8.0\UI Guidelines. Your Form should now resemble Figure 11. See Table 4 for the list of properties and associated values to set on your Form.
We have one step left in our UI layout. Go to the View menu and select the Tab Order menu item. Your cursor will change into a crosshair and every control will have a number superimposed on top of it. Click the controls in the following order:
- "Description" Label
- Textbox
- "Priority" Label
- Combo Box
- OK Button
- Cancel Button
Now, let's write some code. Add properties to the AddTaskDialog to expose a task description and priority, and wire up the properties so that they'll read and write from the appropriate controls on the form.
Now that we have the means to read and write data from our dialog, let's wire it up to the toolbar button. Reopen TasklistPackage.cs, and locate the Initialize() method. Currently, it contains the code shown in Listing 3.
What's happening is that when our Package is first loaded, we request the OleMenuCommandService from Visual Studio and add an Event Handler to the View.Other Windows.Tasklist Sample menu item.
This is a lot like when we wrote the code to add a toolbar to the tool window. We created a CommandID object that represents the CTC-defined command we want to hook. After the CommandID object is created, we construct a MenuCommand object that combines an EventHandler with the CommandID, and then pass it to Visual Studio.
Add the following code to the if statement:
// Create the command for the Add Task Button
CommandID addTaskCommandID = new CommandID(GuidList.guidTasklist_SampleCmdSet,
(int)PkgCmdIDList.cmdidAddTask);
MenuCommand addTaskMenuCmd = new MenuCommand(new EventHandler(AddTask),
addTaskCommandID);
mcs.AddCommand(addTaskMenuCmd);
Now add an AddTask method to your Package. This can be as simple as:
private void AddTask(object sender, EventArgs e)
{
AddTaskDialog atd = new AddTaskDialog();
atd.ShowDialog();
}
Go ahead and run your project again. Click the Add Task button in your tool window's Toolbar and you will see your Add Task dialog appear.
For now, our data access story will be limited. Unfortunately, there's no easy way to supply a data source to a ListView control, so what we'll do for now is add an event handler to forward on the results of an AddTask operation to our ListView in the Tool Window's client area code.
First, open your Package class. We will need to add a static accessor to it so that we can easily subscribe to the event we'll create later.
private static TasklistPackage staticPackage = null;
public static TasklistPackage TasklistSingleton
{
get
{
return staticPackage;
}
}
Next, push your Package instance into the staticPackage variable in your Package's constructor:
TasklistPackage.staticPackage = this;
Next, add a delegate and event to your Package:
public delegate void TaskCreated(object sender, TaskCreatedEventArgs e);
public event TaskCreated OnTaskCreated;
Clearly we'll now need to add the new EventArgs subclass we used above, which is shown in Listing 4. Our AddTask() method needs to take advantage of the new functionality we've added. The changes we make can be seen in Listing 5.
ToolwindowClientArea needs an event handler to deal with these changes. Add the following line of code to its constructor:
TasklistPackage.TasklistSingleton.OnTaskCreated += new
TasklistPackage.TaskCreated(TaskWasCreated);
And then this method:
private void TaskWasCreated(object sender, TaskCreatedEventArgs e)
{
AddTask(e.Description);
}
Conclusion
We've accomplished quite a bit here. We have created a tool window with a fleshed-out user interface, and a standard Visual Studio Toolbar. Now, when you start your project you should see something similar to Figure 13. Congratulations!
Next Steps
Clearly, our Task List still has a ways to go. We need to integrate ourselves into Visual Studio's Task List Service to synchronize with data in the VS Task List. We also need to disable buttons on our tool window's Toolbar when the current context doesn't allow them to function. Look for all this, and more, in the next installment of this article. To download the sample code demonstrated here, please visit http://blogs.msdn.com/aaron brethorst.
Published June 29, 2005 Reads 50,641
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Aaron Brethorst
Aaron Brethorst is a program manager on the Visual Studio Core team, where he is responsible for Accessibility and User Experience across the Visual Studio IDE. Aaron joined Microsoft in 2003 after graduating from the University of Minnesota with a degree in Computer Science. When he's not developing software, you can usually find him in a Seattle coffee shop with a good book.
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications



























