delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
499 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (2)


Custom statusbar to show hints without any codingFormat this article printer-friendly!Bookmark function is only available for registered users!
Slick method to show tooltips
Product:
Delphi 3.x (or higher)
Category:
GUI
Skill Level:
Scoring:
Last Update:
12/27/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet hints tooltips statusbar
Times Scored:
2
Visits:
5707
Uploader: Kevin Gallagher
Company:
Reference: http://www.undu.com/Articles/980820d.html
 
Question/Problem/Abstract:
How do I show tooltips/hints for menu items and any visual control
Answer:



There are several methods to show hints in a statusbar (or similar control), each of these methods requires more then one line of code!

There are more important things to be spending your time on, drop the following code into a file and save it as TheStatusbar.pas, now install it in the Delphi IDE menu
File->Components->Install Component

Once installed drop the statusbar onto a form, set the hint property of one or more controls (do some menu items too for the test). Compile/run the project and while running place the mouse cursor over any of the items which you set the hint property. You should see the hint in the statusbar.


Note: I have not tested this in D6 but be forewarned that "DsgnIntf" in the USES clause will most likely be a problem, if so then remove it and all code that does the About dialog.



unit TheStatusBar;
{*****************************************************************}
{ Description                                                     }
{ Makes it easy to show hints for components and menu items in the}
{ statusbar. All the programmer needs to do is write the text for }
{ the desired item to show hints. You do not have to set ShowHints}
{ to True on a form unless you want ballon style hints also.      }
{                                                                 }
{ Tested with D3 to D5                                            }
{=================================================================}
{ USE TSmartStatusBar AT YOUR OWN RISK.                           }
{ I AM NOT RESPONSIBLE FOR ANY HARM THIS COMPONENT MIGHT CAUSE!!  }
{                                                                 }
{ Kevin S. Gallagher                                              }
{ E-Mail : Gallaghe@teleport.com          Home                    }
{          kevin.s.gallagher@state.or.us  Work                    }
{*****************************************************************}

interface

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

type
  TAbout = class(TPropertyEditor)
  public
    procedure Edit; override ;
    function GetAttributes: TPropertyAttributes; override ;
    function GetValue: string; override ;
  end;

  TSmartStatusBar = class(TStatusBar)
  private
    FSizeGrip: Boolean ;
    FAbout: TAbout ;
    FOldOnHint: TNotifyEvent ;
    FSysOnHint: TNotifyEvent ;
    FShowAppHint: boolean ;
    procedure SetShowAppHint(b : boolean) ;
  protected
    procedure DispAppHint(Sender : TObject) ;
  public
    constructor Create(AOwner: TComponent); override ;
  published
    property About: TAbout read FAbout write FAbout ;
    property ShowAppHint : boolean read FShowAppHint write SetShowAppHint default True ;
  end;

procedure Register;

implementation

uses Commctrl ;

procedure TAbout.Edit ;
begin
  Application.MessageBox('TSmartStatusBar component'  + #13 +
  '1998-2001 Kevin S. Gallagher - This component is freeware.',
  'About TSmartStatusBar Component', MB_OK + MB_ICONINFORMATION) ;
end;

function TAbout.GetAttributes: TPropertyAttributes ;
begin
  Result:= [paMultiSelect, paDialog, paReadOnly] ;
end ;

function TAbout.GetValue: string ;
begin
  Result:= '(about)' ;
end ;

constructor TSmartStatusBar.Create(AOwner: TComponent) ;
begin
  if not(AOwner is TForm) then
    raise EInvalidOperation.Create('Can only drop me on a form') ;

  inherited Create(AOwner) ;
  SimplePanel := True ;
  FSizeGrip := True ;
  FShowAppHint := True ;
  ShowAppHint := True ;
  FSysOnHint := Application.OnHint ;

  { Allow controls to be placed onto this component }
  ControlStyle := ControlStyle + [csAcceptsControls] ;
end ;

procedure TSmartStatusBar.SetShowAppHint(b : boolean) ;
begin
  FShowAppHint := b ;
  if not(csDesigning in ComponentState) then
  begin
    if b then
    begin
      FOldOnHint := Application.OnHint ;
      Application.OnHint := DispAppHint ;
    end else
      Application.OnHint := FOldOnHint ;
  end;
end;

procedure TSmartStatusBar.DispAppHint(Sender : TObject) ;
begin
  if not(csDesigning in ComponentState) then
    if FShowAppHint then
      SimpleText := Application.Hint ;
  if Assigned(FOldOnHint) then
    FOldOnHint(Sender) ;
end;

procedure Register;
begin
  RegisterComponents('Win32', [TSmartStatusBar]);
  RegisterPropertyEditor(TypeInfo(TAbout), TSmartStatusBar, 'ABOUT', TAbout);
end;
end.

Make sure to read the comments below on "AutoHint"


Example code for working with a main form and a child form:
{ Here we stop the hints from being displayed in this the main form
  and show them in the child form.                                    }
procedure TForm1.cmdTestOneClick(Sender: TObject);
var
  f:TfrmChild;
begin
  SmartStatusBar1.ShowAppHint := False ;
  f:= TfrmChild.Create(Self) ;
  try
    f.ShowModal ;
    SmartStatusBar1.ShowAppHint := True ;
  finally
    f.release ;
  end ;
end;

{ Here we stop the hints from being displayed in the child form and
  show them in the main form. Please note that if the child form is
  not disabled then both forms will show the same hint which would
  be confusing to some users.                                         }
procedure TForm1.cmdTestTwoClick(Sender: TObject);
var
  f:TfrmChild;
begin
  f:= TfrmChild.Create(Self) ;
  try
    f.SmartStatusBar1.ShowAppHint := False ;
    f.ShowModal ;
  finally
    f.release ;
  end ;
end;






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
statusbar's autohint
    Antoine (Dec 27 2001 3:48PM)

with borland's standard statusbar, if you set the "autohint" property to true, it will display automatically all the text following a "|" in the hint property of any component. Is it what you tried to implement ?
Respond

RE: statusbar's autohint
Kevin Gallagher (Dec 27 2001 6:41PM)

Yep, but older versions of Delphi didn't have this property. By creating this component w/o using the underlying method used in more recent versions of Delphi a programmer can use D3 to D6 w/o any problems. I tend to work with D3 and D5 thus no conflicts when moving between versions.  

Also it is easier to alter the logic for showing hints in my component if you want to tweak the code. For instance in my personal copy the hint is shown in Panel[1].

Cheers
Kevin
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
C.A. Longen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)