Creating a button bar that auto-hides

Posted on 2001-09-06
Medium Priority
Last Modified: 2010-04-06
I am working on an application that has to display quite some information to the user at one time, and for this reason I want to move some of the navigation functionality to a toolbar that hides when the mouse is elsewhere, and shows when the mouse touches it. Much like the MS Office toolbar when the auto-hide feature is enabled, but NOT like the Windows taskbar. In the latter case the rest of the screen is adjusted when the bar pops out, while I am looking for a solution where the bar is hoovering above the screen.

To my surprise, I could not find any (standard) delphi (5) objects that have an auto-hide property. Trying to implement one myself, I needed an event like OnMouseEnter and OnMouseLeave, but could not find any either.

Does anyone know how to proceed?

Thanks already for any feedback,


Question by:jmvalk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3

Expert Comment

ID: 6461451
you can ovveride, CM_MOUSEENTER and CM_MOUSELEAVE message handlers

Expert Comment

ID: 6461456
Im not sure if i totaly understand you, but this may help you out:

unit Unit1;


  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ToolWin;

  TForm1 = class(TForm)
    ToolBar1: TToolBar;
    procedure FormCreate(Sender: TObject);
    { Private declarations }
    { Public declarations }

  TMyToolBar = class(TToolBar)
    procedure OnMouseEnter(var Msg : TMessage); message CM_MOUSEENTER;
    procedure OnMouseLeave(var Msg : TMessage); message CM_MOUSELEAVE;

  Form1: TForm1;
  ToolBar : TMyToolBar;


{$R *.DFM}

procedure TMyToolBar.OnMouseEnter(var Msg : TMessage);
  {respond to mouse enter}

procedure TMyToolBar.OnMouseLeave(var Msg : TMessage);
  {respond to mouse leave}

procedure TForm1.FormCreate(Sender: TObject);
  ToolBar := TMyToolBar.Create(self);
  with ToolBar do
    Parent := Form1;
    Color := clBlack;
   // Define any other properties...




Expert Comment

ID: 6462740
You can place a big panel (change it's alignment property to alTop) with 2 panels inside. In one of the smaller panels paste all the controls that will show the information you want to show the user (labels I suppose). Make it as big as you believe it's necesary.
On the second panel add a button and change it's Anchors property to akLeft, akRight, akButtom. This will make the button change it's size when you change the size of the big panel.

Then you just need to create an OnClick procedure for the button telling it to show/hide the other 'little' panel.

You can download a program of mine that does just this. It is a favorites manager that has a panel that shows/hide when the user presses this button I talked about.

the URL is http://www.geocities.com/casta_pablo/favkeep.zip

Hope it helps. Paul.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 6462756
you can download the source of this program from

Expert Comment

ID: 6463968
Hi Jm,

If you want the toolbar to hover, it's gonna have to be
a borderless toolwindow. Create a new form class and override the CreateParams procedure and set the appropriate
styles (dunno 'em offhand, I think WS_EX_TOOLWINDOW's one of 'em).

Put a very narrow panel or use an existing control near the top of the main form, when the mouse enters it, pop up and focus the toolbar (window). When the mouse leaves the
tool window, or mouses over one of the mainform controls,
then hide the toolbar.

To capture Mouse enter and leave events, simply add the
following declarations to your form's protected section:

  procedure MouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
  procedure MouseEnter(var msg: TMessage); message CM_MOUSEENTER;

then implement 'em like:

  procedure TToolForm.MouseLeave(var msg: TMessage);
  procedure TMainForm.TopThinPanelMouseOver(Sender: TObject);
    if not ToolForm.Showing then

Accepted Solution

ginsonic earned 800 total points
ID: 6466247
Do you need a bar that resize you mainform ? To see the bar and ALL work area ?

If not I have a sample project how to implement a floating bar that can be move outside screen and transform into a auto-hide bar .
Of course the bar can be set to autohide to begining .

In same time can split the desktop in two part ( if you wish ) : one for bar and one for mainform .

Just put your address here and I will send it to you .

Author Comment

ID: 6467097
First of all, thanks for all your rapid replies.

Pin_plunder's method may be viable, but it's really important for my users when they can use as few mouse-clicks as possible.

Ginsonic's description sounds like what I want. Could you please mail it to j.falcon@12move.nl?

I have been playing around a bit with the posted options, and more or less got what I wanted. I'm going to dig into it some more over the next days but would not like to leave this item open for too long.

What I have now is a main form with a scondary  form that becomes visible when MS-Windows' CM_MOUSEENTER event fires. When CM_MOUSELEAVE fires, the secondary form hides. The problem, however, is to link the events to the correct object. I incorporated a narrow frame, as suggested by Rondi, but since the CM_MOUSEENTER event is linked to the form, it serves no function because I don't know how to create a new procedure for an existing class (ANYONE?)

There are two drawbacks to the current method:
- an extra unit is required for every form using this functionality (in my case this number is 10+). The solution I had hoped for was one where the buttonbar was part of the mainform, placed directly over another object, which would also simplify the implementation of the reaction to buttons-pressed on this buttonbar. However, when that is not an option, I can live with this.
- As it stands now, the procedures having 'message CM_MOUSE_____;' behind them, fire for EVERY occurrence of this event while in the current form, for example, when the mouse is moved over a button on the buttonbar without pressing it, first CM_MOUSEENTER, and then CM_MOUSELEAVE is fired. This happens because CM_MOUSELEAVE is linked to the secondary form, which apparently also causes items on it to respond. Surprisingly, the CM_MOUSELEAVE does NOT fire when the mouse leaves the form itself.

So, I still have some questions:
- How can I link the event (and thus the procedure with the 'message' clause) to an existing class, so that only the right object responds..
- Why does CM_MOUSELEAVE not occur when the mouse leaves the form?
However, the main thing that did the trick was how to react to the MouseEnter and MouseLeave events, and, although slavak mentioned this first, it was alanwhincup who really specified how to do it, even though I feel that his method of defining the procedure of OnMouseEnter and -Leave has no effect for the toolbar (Maybe it works when the modified toolbar is implemented as a new object? But I'm too new to Delphi to work that out right now.) So, having to choose between alanwhincup and rondi I feel that alanwhincup is entitled to the points, (unless you two can share the points, and unless Ginsonic turns out to have a better solution).  Is that OK?


(I may not be able to respond as quickly as you all did, so bear with me a bit)

Author Comment

ID: 6472360
Ginsonic sent me his project and it turned out that it is exactly what I needed, so I will give him the points.
I don't want to post his source code here without his consent, so ginsonic: I'll leave the decision to post it
as a comment, or not, to you.

Thanks to everyone, I learned quite a lot from this one!


Expert Comment

ID: 6473205
I think that is to bigger to put it her :)
But just request and I will send it to you .

See you on net,

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question