Important alert: (current site time 7/16/2013 5:52:34 AM EDT)
 

VB icon

Changing the font name of your hints

Email
Submitted on: 7/9/2000 5:46:53 PM
By: Emiel Hollander  
Level: Beginner
User Rating: By 1 Users
Compatibility: Delphi 5, Delphi 4, Pre Delphi 4
Views: 12233
 
     This tip will tell you how to change the font and other properties of the hint window. You will also learn some things about TCanvas this way.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
!**************************************
! Name: Changing the font name of your hints
! Description:This tip will tell you how to change the font and other properties of the hint window. You will also learn some things about TCanvas this way.
! By: Emiel Hollander
!
!This code is copyrighted and has! limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=58&lngWId=7!for details.!**************************************

First, you need to make a descendant of the THintWindow type. I'll call it TAltHintWindow in this tip. The declaration goes like this: 
type
 TAltHintWindow = class(THintWindow)
constructor Create(AOwner: TComponent); override;
 end;
Please note that there is no semicolon after the second row. You need to place this declaration after the row which says 
{$R *.DFM} 
in the implementation part of the unit. Then you need to fill the constructor of the newly created TAltHintWindow to reflect the changed you would like to see made to the hint window. The first three rows will be like this: 
constructor TAltHintWindow.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
You always have to call the constructor of the class you have descended the new class from, because that class might also need to do some initialization. 
Next, you can make the changes you like to the canvas of this form. You can e.g. change the background colour, or the font name. Try the following for a red hint box with large Times New Roman letters: 
 Canvas.Font.Name := 'Times New Roman';
 Canvas.Font.Size := 18;
 Canvas.Brush.Color := clRed;
If you search Delphi's help for TCanvas you will find lots of other properties you can change to adjust the hintbox to your personal preferences. 
Then, in the Form.Create procedure you have to add the following three lines: 
 Application.ShowHint := false;
 HintWindowClass := TAltHintWindow;
 Application.ShowHint := true;
This code makes sure that the application uses the newly created type TAltHintWindow for the hint windows, instead of the usual THintWindow.


Other 14 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.