Click here to Skip to main content
Click here to Skip to main content

Pretty IE Toolbar in C#

By , 9 Sep 2008
Rate this:
Please Sign up or sign in to vote.
IEToolbarEngineSources

Introduction

One of our clients approached us with an idea to create a commercial toolbar for Internet Explorer. The idea was simple – it was necessary to implement a toolbar for Internet Explorer 7.0 containing the following elements:

  • company logo;
  • search field, allowing to send a search request to an arbitrary site and display the results in the browser;
  • expand buttons, containing arbitrary number of links;
  • drop-down lists displaying RSS-channels.

We started to work on this task and started with a choice of a platform. As it turned out, it is not a simple thing to make a toolbar for Internet Explorer with a declared functionality. It is necessary to deal with Com-components, interact with the browser and store cashed data somewhere. Fortunately, it appeared that it is possible to do everything on the .NET 2.0. platform, which simplified the task a lot.

The result of our work is given below – it is the IEToolbarEngine component, presenting high level interface for toolbars and its elements creation. Perhaps, this component will allow you to implement your own toolbars or you will find some useful data for the implementation of your own projects in the MS Visual Studio environment in the description of this device.

Usage

IEToolbarEngine is inherited from BandObject component, written by Pavel Zolnikov and described in the article “Extending Explorer with Band Objects using .NET and Windows Forms.” We modified it so it would be possible to build our toolbar in Internet Explorer. After that, we wrote a small library of classes enabling to add different elements into the toolbar.

If to speak generally, the toolbar presents itself UserControl with the System.Windows.Forms.ToolStrip component placed on it. At the loading of this control, the CreateToolbarItems function is activated, which should be paid great attention, as the main initialization of a toolbar elements happen in it. You can bring changes into it for the creation of your own toolbar. Its fragment is given below.

internal void CreateToolbarItems ()
{
    try
    {
        …
        //Get current assembly.
        Assembly currentAssembly = Assembly.GetAssembly( this.GetType() );
        
        //Links cration.
        Link link1 = new Link("Home page", "http://kbsoft-group.com/");

        Link link2 = new Link("Clear Search History",
            IEToolbarEngine.WrapInternalCommand(IEToolbarEngine.cmdClearHistory));

		//Getting image from resources
        Image img = Image.FromStream( currentAssembly.GetManifestResourceStream(
            "IEToolbarEngine.main.png") );

		//Create toobar item.
        menu = new MainMenu( this, "Company", "Main", 
                new Link[] { link1, link2 }, img);

       	//Add item to internal collection         
        items.Add (menu);
        …
    }
}

A creation of one toolbar element is demonstrated here, this element contains a logo and a brief drop-down menu. An item is created with the help of the MainMenu class. Two links and an image are added to it. The classes diagram displaying a simple architecture of toolbar elements is given below:

Class deagram

A created element will look like that:

Main menu sample

Title text, tips, array of links (KeyValuePair<string, string> class objects, where Key -- menu item text and value -- link for transfer with a click on it) and a link to the image received from the assembly resources are given to the MainMenu class constructor.

Let us note, for those who are curious, that name of a resource embedded into the assembly is formed from the default namespace name, and from the resource name itself (hence, the line IEToolbarEngine.main.png).

After a creation, it is necessary to add a new element into the collection of IEToolbarEngine Items class.

Creation of several elements is demonstrated in the IEToolbarEngine project attached to this article. Lets view them in consequence.

SearchBoxItem

new SearchBoxItem (this, "<clear>", "terms to serach!",
               "http://www.google.ru/search?q={0}",
               "Search here", "Search", "Click to search",new Size (160, 16), 
               FlatStyle.System, img);

The SearchBoxItem class presents itself a search line with a button starting the search. The line can navigate to an arbitrary site supporting a search with parameters specified in GET request.

The following parameters are specified to the constructor: link to the IEToolbarEngine class, a line which will be displayed in combobox for item of search history clearing, prompt line, search line, pop-up prompt line, text on search button, search field size, its style and a link to the image for search button. This element will look like that:

Main menu sample

A few words about search line format. There is a q={0} parameter in it. Here q is parameter name, used in your search query, and {0} will be automatically substituted to the line which a user enters into search line. If there is another parameter name in your search query, it should be staned instead of q.

LinkListItem

LinkListItem(this, "Advantages", "Advantages", 
                    new Link[] { link1, link2, link3, link4 }, img);

Simple list with links. Constructor parameters -- link to IEToolbarEngine class, button text, tooltip text, massive of elements. The exterior is shown below:

Main menu sample

RssTicker

RssTicker(this, "RSS", "RSS Channel", 
    "http://www.euro2008.uefa.com/rss/index.xml", 1440, img, "RSSChannel");

This element presents itself a list of links received from an RSS feed. For that, a link to RSS-feed and a period of channel update is given to a constructor. The string – a unique name of RSS-channel, which will be used for creation of a cash-file in the application folder in "Application Data\IEToolbar\Cache", should be transmitted the last.

The resulting element looks like that:

Main menu sample

Installation Project

Also, the demo project contains an installation project IEToolbarInstallation, generating a Setup.exe file, which allows you to install the toolbar to the user machine and delete it if necessary. It is created by the means of MS Visual Studio. The moments, connected with the implementation of an installation project which should be paid attention to, are given below.

There is a IEToolbarInstaller class, derived from System.Configuration.Install.Installer in the toolbar assembly (IEToolbar.dll, is created by the IEToolbarEngine project). In order to show the installer that this class method should be started in the process of the installation, it is marked by the RunInstallerAttribute attribute. Install and Uninstall methods are overriden in it. Install implements a registration of a build as COM-server. Uninstall, correspondingly, cancels its registration.

RegisterAssembly function of class RegistrationServices is used for registration. It is necessary to note, that this assembly is not installed in GAC, that is why registration should be implemented with the AssemblyRegistrationFlags.SetCodeBase key. For that, it is necessary for the assembly to be strongly named, otherwise, registration can go in a wrong way.

The installer is given a directive to search this class in the build at the installation and start its actions Install and Uninstall. For that, a new action is added into a "Custom Actions" section in the project, for which, IEToolbr.dll file of a build is selected in the "custom action source" field.

Basics for the IEToolbarEngine class BandObject contains Register and Unregister functions. Register is started in the process of registration and executes adding of keys, necessary to embed the toolbar into Internet Explorer, into the windows register. Unregister is started at the installation and deletes the information, connected with the toolbar, from the windows register.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Alexandr Golovanov
Web Developer
Russian Federation Russian Federation
Alexandr Golovanov is a .NET developer at KB_Soft Group, an offshore software development company located in Russia, Novosibirsk. Here he has worked
on various .NET projects.

Comments and Discussions

 
QuestionCan u reship compiled in Visual Studio 2012? PinmemberHRDTA30-Jan-13 3:56 

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
Web04 | 2.8.140415.2 | Last Updated 9 Sep 2008
Article Copyright 2008 by Alexandr Golovanov
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid