Change Font style in sCheckListBox?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #46158
    IPSteven
    Participant

      You need to use the DrawItem event.

      In the code below I'm using a list box to contain names of the fonts I want and the code cycles through the list.

      Code:
      procedure TForm1.sCheckListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
      var
      i : Integer;
      begin
      i := Index;
      if Index >= (sListBox1.Count – 1) then
      i := Index mod sListBox1.Count;

      with sCheckListBox1.Canvas do
      begin
      FillRect(Rect);
      Font.Name := sListBox1.Items;
      Font.Size := 0; // use font's preferred size
      TextOut(Rect.Left+1, Rect.Top+1, sCheckListBox1.Items[index]);

      //if you don't know what to set the itemheight as
      //since MeasureItem() property doesn't work – you can use this, its ugly but does the job
      i := TextHeight('Wgyj') + 2; // measure ascenders and descenders
      if sCheckListBox1.ItemHeight < i then
      sCheckListBox1.ItemHeight := i;
      end;
      end;

      I haven't messed with changing the font properties (Bold, Italic, etc.) and don't know if its as simple as adding

      Code:
      Font.Style := [fsBold];

      or not.

      I don't know if it is bug in AlphaSkins or not but the MeasureItem() event in sCheckListBox is not firing.

      With a regular list box you could use this event to individually adjust the height of each line as needed.

      Serge – if your checking out this thread maybe you could comment or check it out?

      **Edit – added attachment and image**

      I've attached a sample project demo below.

      [attachment=4970:CheckListBoxDynamicFonts.png]

      [attachment=4969:CheckListBoxDynamicFonts.rar]

      BTW if you want to change the background colors in the CheckListBox check out:

      http://delphi.about.com/cs/adptips2002/a/bltip0602_4.htm

      …Steven

      #46173
      Support
      Keymaster
        'IPSteven' wrote:
        I don't know if it is bug in AlphaSkins or not but the MeasureItem() event in sCheckListBox is not firing.

        With a regular list box you could use this event to individually adjust the height of each line as needed.

        Serge – if your checking out this thread maybe you could comment or check it out?

        Hello

        Try change the style property to lbOwnerDrawVariable.

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.