Drawing Font Face in a TComboBox - [Solved] lazarus / 39-Graphics ---------------------------------------------------------------------- zxandris · 2024-12-17 18:58 Now I'm pretty certain I should've been able to find this, I would imagine it's a common question.  But I think my google-fu has failed me.  So I had a play with what I could find and made this. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmDLGFooterGenerator.cboFontFaceDrawItem(Control: TWinControl;  Index: Integer; ARect: TRect; State: TOwnerDrawState);begin     cboFontFace.canvas.Font.name := cboFontFace.items[index];     if index = cboFontFace.ItemIndex then     begin        cboFontFace.Canvas.Brush.color := clHighlight;        cboFontFace.Canvas.Font.color := clHighlightText;        cboFontFace.Canvas.FillRect(ARect);     end else     begin       cboFontFace.Canvas.Brush.color := clWhite;       cboFontFace.Canvas.Font.color := clBlack;       cboFontFace.Canvas.FillRect(ARect);     end;     cboFontFace.Canvas.TextRect(ARect, 20, ARect.Top, cboFontFace.Items[Index]);end; The problem is that when you run your mouse down the various entries it highlights them in turn so you've got a sea of highlighted entries.  Can anyone kindly help me fix this.  I must admit i just don't know why it's doing it.  I would appreciate the help or even if your google-fu is better please point me at an example Thanks CJ ---------------------------------------------------------------------- Remy Lebeau · 2024-12-17 19:40 You need to look at the State parameter of the event instead of checking the ItemIndex property of the ComboBox, eg: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmDLGFooterGenerator.cboFontFaceDrawItem(Control: TWinControl;  Index: Integer; ARect: TRect; State: TOwnerDrawState);begin  cboFontFace.Canvas.Font.Name := cboFontFace.Items[Index];  if odSelected in State then // <-- HERE!!!  // alternatively:  // if (State * [odSelected,odHotLight]) <> [] then  begin    cboFontFace.Canvas.Brush.Color := clHighlight;    cboFontFace.Canvas.Font.Color := clHighlightText;  end else  begin    cboFontFace.Canvas.Brush.Color := cboFontFace.Color;    cboFontFace.Canvas.Font.Color := cboFontFace.Font.Color;  end;  cboFontFace.Canvas.FillRect(ARect);  cboFontFace.Canvas.TextRect(ARect, 20, ARect.Top, cboFontFace.Items[Index]);end; ---------------------------------------------------------------------- zxandris · 2024-12-17 19:45 Thank you so much, that's sorted that!   I figured it was something simple but I honestly have little experience with owner draw.  So thank you a thousand thank yous! CJ Quote from: Remy Lebeau on December 17, 2024, 08:40:47 pmYou need to look at the State parameter of the event instead of checking the ItemIndex property of the ComboBox, eg: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmDLGFooterGenerator.cboFontFaceDrawItem(Control: TWinControl;  Index: Integer; ARect: TRect; State: TOwnerDrawState);begin  cboFontFace.Canvas.Font.Name := cboFontFace.Items[Index];  if odSelected in State then // <-- HERE!!!  begin    cboFontFace.Canvas.Brush.Color := clHighlight;    cboFontFace.Canvas.Font.Color := clHighlightText;  end else  begin    cboFontFace.Canvas.Brush.Color := cboFontFace.Color;    cboFontFace.Canvas.Font.Color := cboFontFace.Font.Color;  end;  cboFontFace.Canvas.FillRect(ARect);  cboFontFace.Canvas.TextRect(ARect, 20, ARect.Top, cboFontFace.Items[Index]);end;