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;
to WGYKING(修罗是谁?!) 其實我隻希望我選中的行有顏色顯示,我自已會參照你那裡去改。過一下一頂結貼
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;
to jackie168(玉面書生) 我是希望所有被選的(也就是check[index]是true)都突出顏色顯示呀。而不是選一行它就顯示,選另外一行時它就不顯示了.
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;
to WGYKING(修罗是谁?!) ,首先謝謝你呀。 我全部照你的code,不行呀,不知道你自已是否試過
根据 Index 得到 Item[Index] 的 Rect
然后设置 CheckListBox.Canvas.Brush.Color
CheckListBox.Canvas.FillRect(Rect);
CheckListBox.Canvas.TectOut(Rect.Top, Rect.Left, Item[Index]);
CheckListBox1.Canvas.FillRect(CheckListBox1.ItemRect(1) );也就是第
2行吧,結果第2行全部變綠色了。字的都看不到了。我希望隻是加一點顏色突出顯示而已。
看看
我這樣試過,我希望被選中的有顏色突出顯示。如下,但還是不行。
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;
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;
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;
其實一個最主要的問題是,所有被點選的(也就是所有的check[i]:=true)都用顏色突出來顯示。沒有被
點選的就不用突出來顯示了
如果單獨選一行就突出顯示的話,jackie168(玉面書生) 的回復都已經可以了。