Recent

Author Topic: Hint Fontsize  (Read 2627 times)

seghele0

  • Full Member
  • ***
  • Posts: 137
Hint Fontsize
« on: January 04, 2022, 04:37:36 pm »
How can I define the font size and color of the text in the hint?
 :-[
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   SpeedButton1.Hint :='First line ...' +#13+ 'Second line ...';
  4.   SpeedButton2.Hint :='SPButton2 line one' +#13+ 'Second line ...';
  5.   Application.ShowHint:= True;
  6.   Application.HintColor:= clYellow;
  7.   Application.HintHidePause:= 5000;
  8. end;
  9.  

winni

  • Hero Member
  • *****
  • Posts: 3099
Re: Hint Fontsize
« Reply #1 on: January 04, 2022, 04:55:51 pm »
Hi!

Not such an easy thing to do.
Use this workaround:


Code: Pascal  [Select][+][-]
  1. Type
  2.  
  3. TOKHint = class(THintWindow)
  4.      constructor Create(AOwner: TComponent); override;
  5.   end;            
  6.  
  7. constructor TOKHint.Create(AOwner: TComponent);
  8. begin
  9.   inherited Create(AOwner);
  10.   with Canvas.Font do
  11.     begin
  12.       Alignment := taCenter;
  13.       Name  := 'Times New Roman';
  14.       Height := 12;
  15.       Style := [ fsBold ];
  16.       color := clYellow;  
  17.     end;
  18. end;
  19.  
  20. procedure TForm1.FormCreate(Sender: TObject);  
  21. begin
  22. HintWindowClass  := TOKHint;
  23. Application.HintColor := clBlue;
  24. Application.ShowHint := True;
  25. end;

And change the params to your needs.


Winni

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Hint Fontsize
« Reply #2 on: January 04, 2022, 05:14:09 pm »
I checked the following code and found it to work on Windows (did not test others):

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Screen.HintFont.Color := clWhite;
  4.   Screen.HintFont.Name := 'Courier New';
  5.   Screen.HintFont.Size := 12;
  6.   Screen.HintFont.Style := [fsItalic];
  7.   Application.HintColor := clBlack;
  8. end;
  9.  

winni

  • Hero Member
  • *****
  • Posts: 3099
Re: Hint Fontsize
« Reply #3 on: January 04, 2022, 09:08:22 pm »
I checked the following code and found it to work on Windows (did not test others):

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Screen.HintFont.Color := clWhite;
  4.   Screen.HintFont.Name := 'Courier New';
  5.   Screen.HintFont.Size := 12;
  6.   Screen.HintFont.Style := [fsItalic];
  7.   Application.HintColor := clBlack;
  8. end;
  9.  

Hi!

This worked with Delphi  but it did not work for a long time with fpc/Lazarus.

That's why I created the workaround.
Don't know with which version it changed.

Winni

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Hint Fontsize
« Reply #4 on: January 04, 2022, 09:59:19 pm »
It is been working back to 1.8.6, and maybe for the others of the 1.8.x series, too (don't have them any more). 1.6.4 and older seem to ignore the font settings (at least on Windows).

seghele0

  • Full Member
  • ***
  • Posts: 137
Re: Hint Fontsize Change
« Reply #5 on: January 05, 2022, 03:46:54 pm »
Unbelievable how supportive you all are.
This forum is therefore not only for professional programmers, but also for beginners who still have a lot to learn.
 :)

The example with "constructor" can't increase the font size!
Maybe Lazrus hasn't been modified or enabled yet and it probably only works in Delphi. :(
This is a challenge for the professionals
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Buttons, StdCtrls;
  6. type
  7.   { TForm1 }
  8.   TForm1 = class(TForm)
  9.     Button1: TButton;
  10.     Label1: TLabel;
  11.     Label2: TLabel;
  12.     SpeedButton1: TSpeedButton;
  13.     procedure FormCreate(Sender: TObject);
  14.   private
  15.   //
  16.   public
  17.   //
  18.   end;
  19. var
  20.   Form1: TForm1;
  21. implementation
  22. {$R *.lfm}
  23. { TForm1 }
  24. Type
  25.     TOKHint = class(THintWindow)
  26.      constructor Create(AOwner: TComponent); override;
  27.   end;
  28.  
  29. constructor TOKHint.Create(AOwner: TComponent);
  30. begin
  31.   inherited Create(AOwner);
  32.   with Canvas.Font do
  33.     begin
  34.       Alignment := taCenter;
  35.       Name  := 'Arial'; //'Times New Roman';
  36.       Height := 18;
  37.       Style := [ fsBold ];
  38.       color := clBlack; //clYellow;
  39.     end;
  40. end;
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. begin
  44.   HintWindowClass  := TOKHint;
  45.   Application.HintColor := clYellow;//clBlue;
  46.   Application.ShowHint := True;
  47. end;
  48. end.
  49.  
:-X
********************************

Next works well.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   SysUtils, Variants, Classes, Graphics,
  6.   Controls, Forms, Dialogs, StdCtrls, Buttons;
  7. type
  8.   { TForm1 }
  9.   TForm1 = class(TForm)
  10.     Label1: TLabel;
  11.     SpeedButton1: TSpeedButton;
  12.     SpeedButton2: TSpeedButton;
  13.     procedure FormCreate(Sender: TObject);
  14.   private
  15.      //
  16.   public
  17.      //
  18.   end;
  19. var
  20.   Form1: TForm1;
  21. implementation
  22. {$R *.lfm}
  23. { TForm1 }
  24.  
  25. procedure TForm1.FormCreate(Sender: TObject);
  26. begin
  27.    Screen.HintFont.Color := clRed;
  28.    Screen.HintFont.Name := 'Arial'; //'Courier New';
  29.    Screen.HintFont.Size := 14;
  30.    Screen.HintFont.Style := [fsBold];
  31.    Application.HintColor := clYellow;
  32.    SpeedButton1.Hint :='First line ...' +#13+ 'Second line ...';
  33.    SpeedButton2.Hint :='SPButton2 line ...' +#13+ 'Second line ...';
  34.    Application.ShowHint:= True;
  35. end;
  36. end.
  37.  
;) Thanks for the helpful code.

 

TinyPortal © 2005-2018