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

Creating a button bar that auto-hides

Posted on 2001-09-06
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
  • 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.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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 200 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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