Click here to Skip to main content
Click here to Skip to main content
Go to top

Band Objects - .NET 2.0 Redux

, 17 May 2006
Rate this:
Please Sign up or sign in to vote.
A .NET 2.0 version of Pavel Zolnikov's BandObjects project.

As Internet Explorer Toolbar

As Taskbar Toolbar

Preamble

Before you start, I highly recommend you read Pavel Zolnikov's article entitled "Extending Explorer with Band Objects using .NET & Windows Forms" first.

Pavel wrote a fantastic article explaining the ins & outs of using COM Interop to write your own customizable band objects for Explorer using .NET 2003. Without that article, this one wouldn't have come about, so kudos to Pavel.

Introduction

One of the niceties about the .NET 2.0 environment is the rich suite of form controls that have been included for form design. While the 2003 environment was great and all, it was missing a lot of the funky controls such as tool strips and dropdown buttons that we've come to expect as standard in a nice Explorer bar UI. My goal was to design a nice neat tool bar solution so that I had several shortcut links to the sites and systems I used most often, and also to provide 'at-a-glance' information by displaying data in a label which updated on a regular basis.

The 2003 to 2005 Jump

Porting Pavel's 2003 BandObjectLib code to 2005 was a relatively painless experience, so I'll just skim through a few of the minor details:

  1. The first thing to do was to create a standard Windows Class Library.
  2. The ComInterop.cs, BandObject.cs, and Attributes.cs files were taken verbatim from the 2003 project and copied to the 2005 project.
  3. All [assembly: ] attribute code was removed and placed in the AssemblyInfo.cs file instead.
  4. References to SHDocVw (COM tab), System.Drawing, and System.Windows.Forms (.NET tab) were added.
  5. And finally, a strongly named key was added to the library to allow it to be added to the GAC. This is an easier endeavor in the new IDE as you can directly create a .snk file for a project by right-clicking the project file, selecting 'Properties', selecting the 'Signing' tab, and choosing to sign the assembly with a new Strong Named Key.
  6. The final step was to add a post build event to the Project Properties > "Build Events", to add the successfully compiled assembly into the Global Assembly Cache. In VS2005, the gacutil.exe utility is no longer located in the framework folder but in the VS2005/SDK folder under C:\Program Files\. So you may need to alter this script depending on your installation and path setup.
cd $(ProjectDir)bin\Debug

"C:\Program Files\Microsoft Visual Studio 8\
      SDK\v2.0\Bin\gacutil" /if CustomToolbar.dll
"C:\Program Files\Microsoft Visual Studio 8\
      SDK\v2.0\Bin\gacutil" /if Interop.SHDocVw.dll

Note * If you plan on using this software yourself, be aware that Strongly Named Libraries in the GAC are treated as being distinct and separate if they have differing version numbers, so I'd recommend keeping the Assembly Version number in the lib as some static value. E.g.:

[assembly: AssemblyVersion("1.0.0.0")]

Building Our First Toolbar

So we're ready to build our first toolbar. Setting up the project is easy enough. In the attached code, I've just created it as an additional project within the same solution. It's a class library project. It requires direct references to the strong named DLLs in the bin folder of our BandObjectLib project which have already been installed in the GAC. And it needs a strong named key and a static Assembly Version Number.

Step 1. Adding the BandObject Control

Since the BandObject class is essentially a beefed up derived class of UserControl, we can simply add a UserControl to our project and then alter the code-behind so that our control extends a BandObject instead. In this example, I'm creating a horizontal Explorer Toolbar. Since this control will be exposed through COM, we need to specify a GUID attribute to uniquely identify the class. The GUID attribute is part of the System.Runtime.InteropServices namespace.

using BandObjectsLib;
using System.Runtime.InteropServices;

and

[Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")]
    [BandObject("My Toolbar", BandObjectStyle.Horizontal 
    | BandObjectStyle.ExplorerToolbar 
    | BandObjectStyle.TaskbarToolBar, HelpText = "My First Toolbar")]
    public class MyToolBar : BandObject
    { ...

Step 2. Building the Toolbar

You have all the facilities of a standard UserControl at your finger tips through the designer canvas, so feel free to add anything you want from simple buttons to mini-browsers to completely separate forms which popup on a click event. In my example, I've added a ToolStrip and populated it with some standard toolstrip controls: buttons, dropdown buttons, labels, textboxes, separators, and progress bars.

Step 3. Embedded Resources

To make the bar look a little more aesthetically pleasing, I've embedded some PNG images (thanks to www.famfamfam.com's silk icon collection) to an Embedded Resource File in my project and then set the button images. Simply set your toolstrip buttons to display "ImageAndText" or "Image", and specify an image from your resx file. When you compile your toolbar, all the image files will be embedded in the DLL, so there's no need for any installation directories and file bundles. Resource files are very convenient for embedding all sorts of dynamic resources or for making your toolbar multi-lingual.

this.tsbtn1.Image = global::BandObjectsExample.Resources.redcircle;
this.tsbtn1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.tsbtn1.ImageTransparentColor = System.Drawing.Color.Magenta;

Step 4. Code Behind

In my example, I've created a couple of sample buttons to pop open some websites using your system's default browser.

private void OpenWebPage(string url)
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = url;
    process.Start();
}

As an example of a status polling facility, I've created a quick and dirty routine to poll my Winamp web interface for the currently playing track and to display it on a label at the end of the strip. This is performed on a timer which ticks every 30 seconds. Be careful though about having multiple instances of your toolbar (e.g., in multiple browsers) as this might have an adverse effect on your system if the task being performed on the timer occurs very often or is very processor intensive. For my Winamp ticker, I only ever have one instance running on my taskbar beside the system clock.

Step 5. Building Your Toolbar

Once you've finished designing your toolbar in the IDE designer, then it's time to build it and take it for a test drive. You'll need to add a post build job to this project also. The first task is to install your toolbar DLL in the Global Assembly Cache. Since it's going to be used through COM, you'll also need to register your assembly using the Regasm utility contained in the framework installation folder.

cd $(ProjectDir)bin\Debug

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" /if MyToolbar.dll
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm" MyToolbar.dll

Note * By default, .NET 2.0 assemblies are set to be invisible to COM. In your AssemblyInfo.cs file, you'll find an attribute called [Assembly:ComVisible]. This attribute states whether or not the types in your .NET assembly should be exposed to COM. You have to set this value to true, otherwise the Regasm program will not be able to see your toolbar and the registration will fail.

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components. If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

Step 6. Using the Toolbar

Once you've successfully built and registered your toolbar, it should appear on the right click menu of your taskbar and the toolbar context menu in the Internet Explorer. It's worth pointing out that Explorer caches COM objects when they are first loaded, so after doing a rebuild, you might not necessarily see the updates in your toolbar. There are a couple of ways of getting around this such as changing your folder settings to launch folders in new Explorer instances, or to kill the Explorer exe (not recommended Smile | :) ) from your Task Manager.

Ideas, Ideas, Ideas

The sky really is the limit for these band object controls. In my example, I've only shown the ToolStrip control, populated with some buttons and other simple controls. I've added some additional functionalities such as a ContextMenu and the timer control, but there's nothing stopping you from adding any control available. Post them to CodeProject if you come up with a good one Smile | :)

  • You might want to make a vertical toolbar with a mini WebBrowserControl for viewing your favorite web portal.
  • You could write your own RSS ticker to sit on your taskbar beside the clock and rotate through your favorite RSS-feeds.
  • Or maybe you could write an SMS sender to login to your mobile operator's website and send a text message through your account.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

cambo1982
Software Developer (Senior)
Ireland Ireland
Husband, son, brother, I grok technologiy. I write code. I take photos. I teach & practice Krav Maga. I play football. I eat good-food. I drink nice-wine.
Follow on   Twitter   Google+

Comments and Discussions

 
Questionexample tool bar does not show up Pinmembermuharrem18-Jun-12 7:56 
Generalbandobject Pinmemberlifee1-Mar-12 8:40 
Questionhow to set toolbar only for IE, not Explorer Pinmemberhifan30-Dec-10 17:03 
QuestionIE Toolbar background turns black when you drag it down all other toolbars Pinmemberhendrul9-Dec-10 2:37 
GeneralMy vote of 1 Pinmembersunilrakesh21-Jun-10 1:48 
GeneralIE8 problem with ShowBrowserBar Pinmemberstevewentworth29-Jan-10 8:22 
GeneralNot working in IE8 Pinmemberakartik874-Oct-09 22:51 
Questionwhy do we need to gacutil? PinmemberMichael Sync20-Sep-09 5:53 
QuestionHow TO Stop creating new instance of IE Toolbar on new Tab in IE7. Pinmemberramveers17-Sep-09 19:31 
AnswerRe: How TO Stop creating new instance of IE Toolbar on new Tab in IE7. PinmemberTomáš Vrbka9-Aug-10 2:07 
GeneralNice PinmemberMiguel Barros30-Aug-09 14:25 
QuestionDocumentText? Pinmemberjohnmoed22-Jun-09 22:54 
GeneralBandobject PinmemberSalim G27-Apr-09 0:03 
GeneralDoesn't show in IE 7 Tool bar Pinmemberevanw7-Apr-09 5:12 
GeneralRe: Doesn't show in IE 7 Tool bar Pinmemberqbk_skinmaker17-Apr-09 2:38 
AnswerRe: Doesn't show in IE 7 Tool bar Pinmembervmes12-May-09 23:41 
QuestionDropdown does not hides on window moving Pinmember101614-Mar-09 2:39 
Generaltoolbar is not shown PinmemberMember 441328312-Feb-09 21:55 
QuestionHow can I just show it in ie but but not in general explorer? Pinmembermorrischen11-Feb-09 19:40 
Generalside bar is not opened in IE 7 - help Pinmemberamirsas7-Jan-09 23:12 
QuestionManipulate HTML on current page from toolbar Pinmemberjabb100030-Dec-08 0:54 
AnswerRe: Manipulate HTML on current page from toolbar Pinmemberamirsas7-Jan-09 23:21 
QuestionHow to show text in the textbox when toolbar button is clicked? Pinmemberdnramessh12-Dec-08 0:53 
QuestionHelp! Windows Explorer Crashes on logoff PinmemberRon2710-Dec-08 4:21 
QuestionMultiple instances? PinmemberMember 27552878-Dec-08 4:37 
Generalbeforenavigate2 not fired on ie7 Pinmemberstvns31-Oct-08 18:48 
GeneralProblems running toolbar on Vista, IE7 & VS2008 Pinmembersonny123457-Oct-08 14:27 
GeneralRe: Problems running toolbar on Vista, IE7 & VS2008 Pinmemberairkart17-Oct-08 4:11 
GeneralRe: Problems running toolbar on Vista, IE7 & VS2008 Pinmemberjours15-Nov-08 17:37 
GeneralRe: Problems running toolbar on Vista, IE7 & VS2008 Pinmemberryan_johnson1126-Nov-08 10:21 
GeneralRe: Problems running toolbar on Vista, IE7 & VS2008 PinmemberMember 27431565-Mar-09 0:51 
GeneralNeed help Pinmembersonia.sardana4-Sep-08 19:57 
GeneralIE Backspace and arrow keys problem PinmemberGhani_harsha24-Jul-08 22:10 
QuestionIssue of IE Backspace Problem Fix by Kashif Mushtaq Pinmemberangelyaya21-Jul-08 21:40 
GeneralStrange width problem Pinmemberm0r1arty7-Jul-08 3:18 
QuestionSet defaults when loaded (Taskbar) PinmemberNiteShdw13-Jun-08 16:25 
QuestionHow to customize the chevrons/Overflow button? PinmemberMember 354472411-Jun-08 1:20 
GeneralGAC Registration not required! PinmemberGeert van Horrik16-May-08 4:28 
GeneralRe: GAC Registration not required! Pinmemberdamianbc2-Jun-08 9:33 
QuestionShow/Hide IE Explorer Bar Pinmembershah_sunil8113-May-08 19:47 
AnswerRe: Show/Hide IE Explorer Bar Pinmember10168-Jun-08 20:38 
QuestionRe: Show/Hide IE Explorer Bar Pinmembershah_sunil818-Jun-08 21:00 
AnswerRe: Show/Hide IE Explorer Bar Pinmemberamirsas8-Jan-09 19:23 
QuestionToolBar for Internet Explorer only Pinmembershah_sunil8111-May-08 20:52 
Questionhow to fit the window xp theme Pinmemberljf2414-May-08 8:28 
AnswerRe: how to fit the window xp theme Pinmember10168-Jun-08 20:41 
GeneralIE 8 Problem PinmemberVokainer27-Apr-08 3:03 
GeneralPostBuild-Event using VS-macros [modified] PinmemberEkki21-Apr-08 12:32 
Generalfacing problem when running on vista Pinmemberraghda shehab17-Feb-08 3:35 
GeneralRe: facing problem when running on vista PinmemberDanny Weddle14-Mar-08 10:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 17 May 2006
Article Copyright 2006 by cambo1982
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid