Recent

Author Topic: Changing the Font on a CheckListBox  (Read 1490 times)

ahnz

  • Jr. Member
  • **
  • Posts: 57
Changing the Font on a CheckListBox
« on: June 09, 2019, 11:25:48 pm »
Hi All,

I've been playing around with a CheckListBox.. It does everything I need for what I'm doing but I'm having problem getting the Font I want.. Basically I want a fixed width font

I'm attempting to change the font in the FormCreate ...

Code: Pascal  [Select][+][-]
  1. procedure TMyForm.FormCreate(Sender: TObject);
  2. begin
  3.  
  4.   with CheckListBox1.Font do
  5.   begin
  6.     Pitch := fpFixed;
  7.     Name := 'Lucida Console';
  8.     Style := [];
  9.   end;
  10. ....

It's doesn't make any difference.

If I set the CheckListBox style to lbOwnerDrawFixed with a OnDrawItem...

Code: Pascal  [Select][+][-]
  1. procedure TMyForm.CheckListBox1DrawItem(Control: TWinControl; Index: integer; ARect: TRect; State: TOwnerDrawState);
  2. var
  3.   Flags: longint;
  4. begin
  5.  
  6.   with (Control as TCheckListBox) do
  7.   begin
  8.     Canvas.FillRect(ARect);
  9.     Flags := DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX;
  10.     DrawText(Canvas.Handle, PChar(Items[Index]), Length(Items[Index]), ARect, Flags);
  11.   end;
  12.  
  13. end;

Then the font change works, but the Checkboxes disappear.

I have no idea what those flags mean. This is a stripped down example I found for change the Font colour

Does anyone have any idea how I might otherwise change the font and keep the checkboxes ?

Thanks in advance
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Changing the Font on a CheckListBox
« Reply #1 on: June 10, 2019, 03:30:56 pm »
Lucida Console ? On a Mac ?
I thought that's a Windows font ...  :)

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.  i: integer;
  4. begin
  5.   for i:= 0 to 50 do
  6.     clbNames.Items.Add('Hello World'+' '+IntToStr(i));
  7.  
  8.  
  9.   clbNames.Font.Size   := 14;
  10.   clbNames.Font.Quality:= fqAntialiased;
  11.   clbNames.Font.Name   := 'Lucida Console';
  12.   clbNames.Font.Color  := clBlue;
  13.   clbNames.Font.Style  := [fsBold];
  14. end;

On Windows with LAZ 2.1.0 FPC 3.3.1 and LAZ 2.0.2 FPC 3.0.4 everything works well ...

Flag DT_NOPREFIX
Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off. For example,

Example:
input string: "A&bc&&d"
normal: "Abc&d"
DT_NOPREFIX: "A&bc&&d"
Compare with DT_HIDEPREFIX and DT_PREFIXONLY.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Changing the Font on a CheckListBox
« Reply #2 on: June 10, 2019, 10:43:13 pm »
Thanks RAW,

Lucida Console ? On a Mac ?
I thought that's a Windows font ...  :)

Most likely has its origins there, but it is available on Mac.

It turns out, after trying just your code, that this works fine on Carbon, but not on Cocoa unless its OwnerDraw  :(

Anyone got any ideas on how to do to make the CheckListbox work properly?

Thanks
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Changing the Font on a CheckListBox
« Reply #3 on: June 10, 2019, 10:55:16 pm »
A lot of controls are managed via the OS so you may run into restrictions as to what you want to
do. OwnerDraw solves this by allowing you to do anything you want.

 With OwnerDraw you need to handle the OnDrawItem event which gives you all the info needed
to draw the current area in the rect...
The only true wisdom is knowing you know nothing

ahnz

  • Jr. Member
  • **
  • Posts: 57
Re: Changing the Font on a CheckListBox
« Reply #4 on: June 13, 2019, 04:04:53 am »
Thanks all.

I n the end I simply added a bunch of Checkboxes into a Scroll box - does the job nicely
OS: OSX High Sierra 10.13.6
Lazarus: 2.1.0, r61162

Widgetset: Cocoa
Target: 64bit OSX

Compiler:
FPC 3.0.4 [2017/11/26] for x86_64

Debug:
LLDB  (with fpdebug)(Beta)
Path: /usr/bin/lldb
Version: lldb-1000.11.38.2

 

TinyPortal © 2005-2018