Click here to Skip to main content
13,087,235 members (59,745 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 17 Dec 2007

TDHAppBar - A Library to Convert a Windows.Forms.Form into an Application Desktop Toolbar

, 18 Dec 2007
Rate this:
Please Sign up or sign in to vote.
This article describes a class which may be used to convert any Windows.Forms.Form into a docked Application Desktop Toolbar. That is, by use of the AppBar.ApplicationDesktopToolbar class, one's Toolbar applet may be either floating or docked to an edge of the Desktop.
Screenshot -


Recently, I was in the market for code to enable Desktop docking of a small toolbar applet. I came across this CodeProject article from 2003, C# does Shell, Part 3, which seemed at first to be just what I wanted. (I don't at all mean to slight "arikp's" article or code: it's a well written and informative article; the code just wasn't what I needed for the task at hand.) And, in fact, rather than going into technical details in this article, I refer the reader back to "arikp's" original article, of which the present article is purely derivative.

Fortunately for me, in the comments section to the above referenced article, back in December of 2006, "GWB@s1c" posted code answering the particular issues I had.

Since "GWB@s1c" hasn't written an article on his code (and since I've added my own particular spin to it), I submit this article to make the code more readily available to the CodeProject community.

The 'AppBar.ApplicationDesktopToolbar' Class

TDHAppBar is strictly the name for this article and of the project/assembly I've written based on the original code; the namespace and class-name are AppBar.ApplicationDesktopToolbar as in the original code example "GWB@s1c" posted last December. It was my intention to make minimal changes to the original code and to clearly delineate my changes; thus I've retained the original namespace and class-name (while giving my project a unique name, should "GWB@s1c" ever choose to submit an article on some version of his code).

Using The 'AppBar.ApplicationDesktopToolbar' Class

To use AppBar.ApplicationDesktopToolbar as is, add a reference in your project to the class library TDHAppBar.dll. Example usage follows:

using AppBar;
private AppBar.ApplicationDesktopToolbar appBar = null;
private void cmnuMain_Dock_Click(object sender, System.EventArgs e)
    AppBar.AppBarEdges theAppBarEdge = AppBar.AppBarEdges.Right;    // example

    if (this.appBar == null)
        appBar = new AppBar.ApplicationDesktopToolbar(
            this, theAppBarEdge,
            // HorizConfig delegate
            new AppBar.AltitudeConfigDelegate(this.Configure_Horizontal),
            // VertConfig delegate
            new AppBar.AltitudeConfigDelegate(this.Configure_Vertical),  
            // AutoHideConfig delegate
            new AppBar.AutoHideChangedDelegate(this.Configure_AutoHide), 
            // Docking dimensions (max height OR max width, depending upon .Edge)
            106, 82,  
            false);    // set .AutoHide
    if (this.appBar.Edge != theAppBarEdge)
        appBar.Edge = theAppBarEdge;    // Change the Docked .Edge


private void Configure_AutoHide(bool asAutoHide)
    // do something
private void Configure_Horizontal(bool asDocked)
    // do something

private void Configure_Vertical(bool asDocked)
    // do something

private void cmnuMain_DockAutoHide_Click(object sender, System.EventArgs e)
    if (this.appBar != null)
        this.cmnuMain_DockAutoHide.Checked = !this.cmnuMain_DockAutoHide.Checked;
        this.appBar.AutoHide = this.cmnuMain_DockAutoHide.Checked;
        this.cmnuMain_DockAutoHide.Checked = false;
        this.cmnuMain_DockAutoHide.Enabled = false;

private void cmnuMain_Float_Click(object sender, System.EventArgs e)
    if (this.appBar != null)
        if (!this.appBar.UnDock(AppBar.Altitude.Horizontal))    // example
        this.appBar = null;

The TDHAppBar project was written (and compiled) using Visual Studio 2003 (.NET 1.1). Converting it to .NET 1.0, if necessary, should be a straight forward matter of adding the ApplicationDesktopToolbar.cs and ShellApi.cs source code files to one's project.

Points-of-Interest of the 'AppBar.ApplicationDesktopToolbar' Class

Some of the methods of the class do have the potential for throwing exceptions. These are related to either a failure to register the Form as an AppBar or a failure to "de-register" it. For instance, the class constructor itself could possibly throw an exception (so, the example code above really ought to take that into account). The set accessor for the .Edge property also has the potential to throw an exception, since it sets the AppBar Form to a different Desktop edge by first "de-registering" the AppBar and then creating/registering a new AppBar as docked to the new edge.

The constructor for my version of the AppBar.ApplicationDesktopToolbar class records various properties of the Form being converted to an AppBar. These values are used to restore the Form to its original state when the .Undock() or .Dispose() methods are executed. Some signatures of the .Undock() method allow for new values to be given for some of these properties.

With my version of the class, it is not necessary that the original Form's [.FormBorderStyle == FormBorderStyle.None]; - the class will make that change when converting the Form to an AppBar. And, when converting it back to a standard Form, the class restores this property value. Nor is it necessary that the original Form's [.TopMost == true]; - the class will set this property as necessary.

The members-of-interest of the namespace AppBar are:

  • AppBar.Altitude - The elements of this enum indicate to the instance of the AppBar.ApplicationDesktopToolbar class which configuration delegate (if given to the constructor) to invoke when UnDocking the AppBar Form (i.e. converting it back to a standard Form).
  • AppBar.AppBarEdges - The elements of this enum indicate which Desktop edge the instance of the AppBar.ApplicationDesktopToolbar class is to dock the AppBar Form.
  • public delegate void AltitudeConfigDelegate(bool asDocked) - The appropriate instance of this delegate (if given to the constructor) is invoked by the instance of the AppBar.ApplicationDesktopToolbar class as necessary to reconfigure the AppBar Form between vertical and horizontal orientations.
  • public delegate void AutoHideChangedDelegate(bool asAutoHide) - This delegate (if given to the constructor) is invoked by the instance of the AppBar.ApplicationDesktopToolbar class when its .AutoHide property changes.

The members-of-interest of the interface of class AppBar.ApplicationDesktopToolbar are:

  • AutoHide - This property gets or sets whether the instance of the AppBar.ApplicationDesktopToolbar class has been instructed to autohide the AppBar Form.
  • Edge - This property gets or sets which Desktop edge the instance of the AppBar.ApplicationDesktopToolbar class is to dock (or re-dock) the AppBar Form.
  • UnDock() - This method (of which there are various signatures) converts the AppBar Form back into a standard Form. Calling .UnDock() with no arguments attempts to return the Form to its state before it was converted to an AppBar; the other signatures may be used to specify a new state for the Form.
  • Dispose() - In my version of the class, this method is essentially the same as .UnDock() with no arguments.


  • 2007 December 17: Submission of TDHAppBar project Version 1.0.001 to The Code Project
  • 2007 December 18: Version 1.0.002:
    • Fixed a minor annoyance with the .AutoHide mode -- when the AppBar Form had been set to .AutoHide, the context menu might vanish before one had a chance to make a selection.


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


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionThanks and .. Pin
Mazen el Senih4-Apr-13 8:38
memberMazen el Senih4-Apr-13 8:38 
Any way to make it stick to desktop when set focus to desktop by pressing the 'show desktop' shortcut?
There is always hope ..!

AnswerRe: Thanks and .. Pin
Ilíon7-Apr-13 10:56
memberIlíon7-Apr-13 10:56 
SuggestionRe: Thanks and .. Pin
Mazen el Senih9-Apr-13 1:56
memberMazen el Senih9-Apr-13 1:56 
GeneralMy vote of 5 Pin
Mazen el Senih4-Apr-13 8:27
memberMazen el Senih4-Apr-13 8:27 
GeneralRe: My vote of 5 Pin
Ilíon7-Apr-13 10:54
memberIlíon7-Apr-13 10:54 
AnswerRe: My vote of 5 Pin
Mazen el Senih9-Apr-13 1:25
memberMazen el Senih9-Apr-13 1:25 
QuestionVery Useful not enough.... Pin
csharpcomeintome13-Jan-13 21:35
membercsharpcomeintome13-Jan-13 21:35 
GeneralMy vote of 3 Pin
csharpcomeintome13-Jan-13 21:34
membercsharpcomeintome13-Jan-13 21:34 
GeneralRe: My vote of 3 Pin
Ilíon14-Jan-13 2:12
memberIlíon14-Jan-13 2:12 
Bugif you have a vertical task bar it does not work correctly! Pin
I_Need_Help14-Feb-12 4:47
memberI_Need_Help14-Feb-12 4:47 
GeneralShow without focus Pin
Euroged18-Jun-10 0:58
memberEuroged18-Jun-10 0:58 
GeneralRe: Show without focus Pin
Ilíon18-Jun-10 7:13
memberIlíon18-Jun-10 7:13 
QuestionMultiMonitor problem Pin
Member 198564111-Mar-08 23:09
memberMember 198564111-Mar-08 23:09 
GeneralRe: MultiMonitor problem Pin
Ilíon12-Mar-08 2:02
memberIlíon12-Mar-08 2:02 
AnswerRe: MultiMonitor problem Pin
jmcc2k12-Nov-08 23:24
memberjmcc2k12-Nov-08 23:24 
GeneralLock Computer Pin
thomas.foote19-Feb-08 0:45
memberthomas.foote19-Feb-08 0:45 
GeneralRe: Lock Computer Pin
Ilíon19-Feb-08 2:19
memberIlíon19-Feb-08 2:19 
GeneralRe: Lock Computer Pin
thomas.foote19-Feb-08 2:41
memberthomas.foote19-Feb-08 2:41 
QuestionRe: Lock Computer Pin
thomas.foote28-Feb-08 23:28
memberthomas.foote28-Feb-08 23:28 
GeneralRe: Lock Computer Pin
Ilíon12-Mar-08 1:57
memberIlíon12-Mar-08 1:57 
GeneralRe: Lock Computer Pin
Yaroslav Trofimov20-Apr-08 23:36
memberYaroslav Trofimov20-Apr-08 23:36 
GeneralRe: Lock Computer Pin
TomasFangs1-Jul-08 3:36
memberTomasFangs1-Jul-08 3:36 
QuestionWho to resize appbar when docked an edge? Pin
ccchai17-Feb-08 20:10
memberccchai17-Feb-08 20:10 
GeneralRe: Who to resize appbar when docked an edge? Pin
Ilíon18-Feb-08 5:08
memberIlíon18-Feb-08 5:08 
GeneralVB version Pin
HR18023-Jan-08 21:29
memberHR18023-Jan-08 21:29 
GeneralRe: VB version Pin
Ilíon23-Jan-08 5:12
memberIlíon23-Jan-08 5:12 
GeneralRe: VB version Pin
HR180224-Jan-08 8:19
memberHR180224-Jan-08 8:19 
GeneralRe: VB version Pin
Ilíon24-Jan-08 8:37
memberIlíon24-Jan-08 8:37 
GeneralRe: VB version Pin
snrch44511-May-11 8:34
membersnrch44511-May-11 8:34 
GeneralVery grateful Pin
gw_msw19-Dec-07 1:22
membergw_msw19-Dec-07 1:22 
GeneralRe: Very grateful Pin
Ilíon19-Dec-07 2:03
memberIlíon19-Dec-07 2:03 
GeneralRe: Very grateful Pin
Prasad Kopanati3-Jan-08 7:25
memberPrasad Kopanati3-Jan-08 7:25 
GeneralRe: Very grateful Pin
Ilíon4-Jan-08 2:43
memberIlíon4-Jan-08 2:43 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 18 Dec 2007
Article Copyright 2007 by Ilíon
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid