我用checklistbox框,裡面有10行,我任意選其中3或2行,我希望被選中的行顯示紅色,怎麼做呢?

解决方案 »

  1.   

    得到你选取的行的 Index,
    根据 Index 得到 Item[Index] 的 Rect
    然后设置 CheckListBox.Canvas.Brush.Color
    CheckListBox.Canvas.FillRect(Rect);
    CheckListBox.Canvas.TectOut(Rect.Top, Rect.Left, Item[Index]);
      

  2.   

    在.NET技术中,好象这种问题已经加入到控件属性里了。你找找看
      

  3.   

    to : budded(System is bussy!)   你這個方法我試過,比如CheckListBox1.Canvas.Brush.Color :=clGreen  ;
                          CheckListBox1.Canvas.FillRect(CheckListBox1.ItemRect(1) );也就是第
    2行吧,結果第2行全部變綠色了。字的都看不到了。我希望隻是加一點顏色突出顯示而已。
      

  4.   

    CheckListBox.Canvas.TectOut(Rect.Top, Rect.Left, Item[Index]);// 这样字就出来了
      

  5.   

    http://community.csdn.net/Expert/topic/3364/3364467.xml?temp=.9200251
    看看
      

  6.   

    to : budded(System is bussy!) 
    我這樣試過,我希望被選中的有顏色突出顯示。如下,但還是不行。
      i:=CheckListBox1.ItemIndex ;  if CheckListBox1.Checked[i] then
      begin
         CheckListBox1.Canvas.Brush.Color :=clGreen  ;
        CheckListBox1.Canvas.FillRect(CheckListBox1.ItemRect(i) );
        CheckListBox1.Canvas.TextOut(CheckListBox1.ItemRect(i).top  ,CheckListBox1.ItemRect(i).Left , CheckListBox1.Items[i]);
      end;
      

  7.   

    to  WGYKING(修罗是谁?!)    其實我隻希望我選中的行有顏色顯示,我自已會參照你那裡去改。過一下一頂結貼
      

  8.   

    procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
    var index:integer;
    begin
      if checklistbox1.Checked[checklistbox1.ItemIndex] then
      begin
       index:=checklistbox1.ItemIndex;  
       Checklistbox1.Canvas.Font.Color:=clred;
       CheckListBox1.Canvas.TextOut(18,index*13,Checklistbox1.Items[Index]);
    end;
    end;
      

  9.   

    to jackie168(玉面書生) 我是希望所有被選的(也就是check[index]是true)都突出顏色顯示呀。而不是選一行它就顯示,選另外一行時它就不顯示了.
      

  10.   

    procedure TForm1.CheckListBox1MeasureItem(Control: TWinControl;
      Index: Integer; var Height: Integer);
    begin
      Height := 18;
    end;procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
      Index: Integer; Rect: TRect; State: TOwnerDrawState);
    var
      TempColor: TColor;
    begin
      if CheckListBox1.Checked[Index] then begin
        CheckListBox1.Canvas.Brush.Color := clHighlight;
        TempColor := clRed;
      end else begin
        CheckListBox1.Canvas.Brush.Color := CheckListBox1.Color;
        TempColor := clBlack;
      end;  CheckListBox1.Canvas.FillRect(Rect);  CheckListBox1.Canvas.Font.Color := TempColor;
      CheckListBox1.Canvas.TextOut(Rect.Left, Rect.Top, CheckListBox1.Items[Index]);
    end;procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
    begin
      CheckListBox1.Invalidate;
    end;
      

  11.   

    to  WGYKING(修罗是谁?!) ,首先謝謝你呀。 我全部照你的code,不行呀,不知道你自已是否試過
      

  12.   


      其實一個最主要的問題是,所有被點選的(也就是所有的check[i]:=true)都用顏色突出來顯示。沒有被
    點選的就不用突出來顯示了
      

  13.   

    CheckListBox1.Style := lbOwnerDrawVariable
      

  14.   


      如果單獨選一行就突出顯示的話,jackie168(玉面書生) 的回復都已經可以了。
      

  15.   

    行了,謝謝WGYKING(修罗是谁?!),我馬上結貼。OK!