Finding what you need in the Microsoft® Visual Studio® 2005 documentation, which has over 200,000 topics, can be a daunting task. The Doc Detective is here to help, utilizing his investigative skills to probe the depths of the documentation.

Can’t find what you’re looking for? Just ask - if it’s in there, I’ll find it for you; if it isn’t, I’ll let you know that as well (and tell you where else you might go to find it).

Have a question for the Doc? Send your questions for future columns to me at docdetec@microsoft.com.

Dear Doc Detective,

I’m working on a Windows Forms application for a client and I have a base form that all of the forms in the solution inherit from. I know you can catch all unhandled exceptions on an application level, but I want each form to catch its own errors and then process them in the base class, similar to what you can do in ASP.NET where you can catch any unhandled exceptions thrown on a particular page. Is this possible in Windows Forms?

- Baseless in Baltimore

Dear Baseless,

Yes, it’s possible-anything else I can help you with? Okay, okay... so I guess you also want to know how? Although it isn’t well documented, you can catch form-level exceptions in the Application.ThreadException event.

Attach your event handlers to the ThreadException event to deal with any unhandled exceptions, which would otherwise leave your application in an unknown state. Of course, where possible, you should use a structured exception handling block to handle your exceptions. That should handle it!

- Doc D

Dear Doc Detective,

We’re migrating a fairly large Visual Basic 6 app over to Visual Basic 2005-for the most part it has gone smoothly, but we seem to have run into a major issue. The app includes a printing module that includes numerous reports, all of which use the Printer object.

I was dismayed to discover that the Upgrade wizard doesn’t upgrade any of the Printer code, and Help isn’t any help-it just tells me to use the new PrintDocument instead. Please tell me that there is some alternative to rewriting literally thousands of lines of printing code.

--Furious in Fullerton

Dear Furious,

If you had asked me a couple of months ago the answer would have been to rewrite your code, but fortunately there is now an easier solution. Microsoft recently released the Printer Compatibility Library, the third in a series of Visual Basic Power Pack downloads.

By simply adding a reference to the Printer Compatibility Library, declaring a Printer, and making a few minor syntax changes, your project will be able to print using the Printers collection and Printer object as it did in Visual Basic 6. You can download it for free from the Visual Basic 2005 Power Packs page on MSDN-and while you’re there, stop in at the Power Pack Suggestion Center and vote on what you would like to see next.

- Doctor D

Dear Doc Detective,

I’m designing an application that will run primarily in the background without user intervention. I want to put a little icon on the taskbar that the user can double-click to open a configuration dialog box-something similar to the Windows Update icon. I’ve searched the index under “icons” and “taskbar,” but I can’t seem to find anything telling me how to do this.

- Stumped in Steubenville

Dear Stumped,

It’s just a matter of terminology-you are supposed to know that the taskbar has a “notification area” and the icon is called a “notification icon.” From there you should just naturally understand that what you need is a NotifyIcon component. Never mind that it’s indexed under “system tray,” which is the unofficial name for the notification area. Clear as mud, right?

The topic “How to: Add Application Icons to the Taskbar with the Windows Forms NotifyIcon Component” should get you started.

The one thing that the topic doesn’t discuss is how to get rid of the icon once your dialog closes. You will need to set the NotifyIcon component’s Visible property to false in the form’s Closing event, otherwise the icon will remain in the system tray.

Now, as for the icon itself-I would gladly supply you with a picture of the good Doc that you could use....

- the Doc

Dear Doc Detective,

I’m running into issues with the behavior of a transparent label control on top of a picture box. When adding a transparent label control to a form with a background image, the label displays correctly and shows the background.

When you add a picture box control and add another transparent label on top of said picture box, the transparent label control on top of a picture box does not display correctly-the background doesn’t show through. What’s up with that?

-- Blocked in Bloomington

Dear Blocked,

What you are seeing is a known limitation of Windows Forms. Labels are transparent to their container or parent-not to the control underneath them. Windows does not support transparency so Windows Forms fake it by painting the parents background inside the bounds of the label.

Fortunately there are a couple of ways to work around this, neither of which involves a label. You could draw the text yourself in the parent form’s Paint event. For information on drawing text, look for the topic “How to: Draw Text at a Specified Location”.

Alternatively, you can remove the PictureBox control and draw its contents in the Paint event. The topic “How to: Load and Display Bitmaps” explains how to draw an image on a form.

Either solution will allow your floating label to have the correct transparent behavior.

-- Doc Detective

Doc’s Doc Tip of the Day

Want to make sure that your Help is always up-to-date? If so, you should consider using the online version of the Visual Studio documentation. The online library was recently updated with hundreds of new and updated topics for Visual Studio Service Pack 1.

The updated Help isn’t included in the Service Pack, so until the updates are released in the next MSDN Quarterly DVD there is no way to access them locally.

Another benefit to using the online documentation is the ability to access Community Content-a new section where anyone can add clarifications, corrections, and sample code that supplements the documentation. This feature, formerly known as the Developer Wiki when it was in Beta form, is now an integral part of the MSDN Library, and that alone makes switching to online an attractive option.

To switch from using local docs to online, from the Tools menu pick Options and in the Help viewer, select Online, and in the “When loading Help content” section check “Try online first, then local”.

Found a topic in Help that doesn’t help? Tell the Visual Studio documentation team about it at vsdocs@microsoft.com.

URLs

http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.threadexception(VS.80).aspx

http://msdn2.microsoft.com/en-us/vbasic/aa701257.aspx

https://connect.microsoft.com/vbasic

http://msdn2.microsoft.com/en-us/library/062478za(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/b87ey14t(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/8tda2c3c.aspx