Results 1 to 8 of 8

Thread: combobox aanpassen

  1. #1

    combobox aanpassen

    Van een combobox wil ik net zoals bij mijn popup menu's de blauwe balk waarmee de items gehighlited worden aanpassen aan mijn eigen kleur.
    Bij mijn popup kan dit via een ondrawitem.

    Nu wil ik het zelfde doen voor de combobox maar de code die daar staat wordt niet uitgevoerd. (Getest door er een showmessage in te zetten)

    wat zie ik over het hoofd

    Code:
    procedure Tmainform.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
    //  inherited;
    //if (odselected in state)or (odfocused in state) then
    //begin
    with combobox1 do
    begin
      Canvas.brush.Style := bsSolid;
      Canvas.brush.color := $00DCCFC7;
      Canvas.FillRect(Rect);
      Canvas.font.Color:=clblack;
    end; 
     //combobox1.Canvas.TextOut(rect.right-combobox1.Canvas.TextWidth( combobox1.Items[index].text)-3  ,rect.Top+2,combobox1.items[index].Text);
    //end;
    
    end;

  2. #2
    notice-itter SvG's Avatar
    Join Date
    Apr 2002
    Location
    's-Hertogenbosch
    Posts
    4,865
    Heb je OwnerDraw wel op true gezet?
    !

  3. #3
    Voor zover ik weet heeft een combobox geen ownerdraw.
    Of bedoel je de ownerdraw van het formulier?

    edit typo
    Last edited by cpri; 17-Feb-05 at 09:16.

  4. #4
    Ik heb het gevonden. De ownerdrawitem wordt alleen aangeroepen als de style van de combobox csOwnerdrawvariable of csOwnerdrawfixed is.
    Hier is de code om de kleur van je selector te veranderen

    Code:
    procedure Tmainform.drawcombo(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var txt:string;
    begin
    inherited;
    if Control is TComboBox then
    begin
     with TComboBox(Control) do
     begin
      if (odselected in state)or (odfocused in state) then
      begin
       Canvas.brush.Style := bsSolid;
       Canvas.brush.color := $00DCCFC7;
       Canvas.FillRect(Rect);
       Canvas.font.Color:=clblack;
       txt:=Items.Strings[index];
       Canvas.TextOut(rect.left+2,rect.Top,txt);
      end
      else
      begin
       Canvas.brush.Style := bsSolid;
       Canvas.brush.color := color;
       Canvas.FillRect(Rect);
       Canvas.font.Color:=clblack;
       txt:=Items.Strings[index];
       Canvas.TextOut(rect.left+2,rect.Top,txt);
      end;
     end;
    end;
    end;

  5. #5
    Kan korter en uit de losse pols
    Code:
    procedure Tmainform.drawcombo(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    const
      BrushKleur:array[boolean] of TColor = (clHighlight, $00DCCFC7);
    var 
      txt:string;
    begin
      inherited;
      if not (Control is TComboBox) then
        exit;
      with TComboBox(Control) do
      begin
        Canvas.brush.Style := bsSolid;
        Canvas.brush.color :=BrushKleur[(odselected in state)or (odfocused in state)];
        Canvas.FillRect(Rect);
        Canvas.font.Color:=clblack;
        txt:=Items.Strings[index];
        Canvas.TextOut(rect.left+2,rect.Top,txt);
      end
    end;
    DeX 3 Delphi := The ease of VB with the power of C; Zoekt en gij zult vinden

  6. #6
    Ex-Student
    Join Date
    Feb 2004
    Location
    Leeuwarden
    Posts
    2,409
    [offtopic]

    waarom:
    Code:
      inherited;
      if not (Control is TComboBox) then
        exit;
      with TComboBox(Control) do
      begin
        Canvas.brush.Style := bsSolid;
    en niet:
    Code:
      inherited;
      if (Control is TComboBox) then
        with TComboBox(Control) do
        begin
          Canvas.brush.Style := bsSolid;
    scheelt maar liefst 1 regel

    [/offtopic]

  7. #7
    scheelt maar liefst 1 regel
    En scheelt geen enkel byte machinecode!
    Het recht is als licht, het kan gebogen worden

  8. #8
    Voor de compiler maakt het niets uit maar ikzelf vind dat leesbaarder, nu hoef je niet te kijken waar een begin-end block eindigt om te zien dat er toch geen code meer komt die moet uitgevoerd worden.
    DeX 3 Delphi := The ease of VB with the power of C; Zoekt en gij zult vinden

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Combobox vorig item
    By Joeri in forum Algemeen
    Replies: 3
    Last Post: 25-Oct-04, 10:42
  2. weergave item uit een combobox
    By rigga in forum Algemeen
    Replies: 4
    Last Post: 29-Mar-04, 12:27
  3. waarde in combobox selecteren
    By Froestie in forum Databases
    Replies: 3
    Last Post: 05-Dec-03, 23:41
  4. Categorie?½n in een ComboBox
    By PsychoMark in forum Tiphoek
    Replies: 0
    Last Post: 15-Apr-03, 10:51
  5. ComboBox probleempje
    By MarcoS in forum Algemeen
    Replies: 4
    Last Post: 22-Aug-02, 21:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •