Solved

Creating a button bar that auto-hides

Posted on 2001-09-06
9
452 Views
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,

regards,

Jm
0
Comment
Question by:jmvalk
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 3

Expert Comment

by:Slavak
Comment Utility
you can ovveride, CM_MOUSEENTER and CM_MOUSELEAVE message handlers
0
 
LVL 5

Expert Comment

by:alanwhincup
Comment Utility
Im not sure if i totaly understand you, but this may help you out:

unit Unit1;

interface

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

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

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

var
  Form1: TForm1;
  ToolBar : TMyToolBar;

implementation

{$R *.DFM}

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

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

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

end.

Cheers,

Alan
0
 

Expert Comment

by:pin_plunder
Comment Utility
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.
0
 

Expert Comment

by:pin_plunder
Comment Utility
you can download the source of this program from
http://www.geocities.com/casta_pablo/favkeepsrc.zip
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:rondi
Comment Utility
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);
  begin
    Hide;
  end;
 
  ...
  ...
 
  procedure TMainForm.TopThinPanelMouseOver(Sender: TObject);
  begin
    if not ToolForm.Showing then
    begin
      ToolForm.Show;
      ToolForm.SetFocus;
    end;
  end;
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 200 total points
Comment Utility
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 .
0
 

Author Comment

by:jmvalk
Comment Utility
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?

Jm

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

Author Comment

by:jmvalk
Comment Utility
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!

Jm
0
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
I think that is to bigger to put it her :)
But just request and I will send it to you .

See you on net,
Nick
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now