(Gast)
n/a Beiträge
|
AW: ListBox Items Brush zweifarbig?
4. Mai 2017, 17:43
Hier ein Beispiel
Delphi-Quellcode:
// aListBoxBrushColor: array [Boolean] of TColor = (clRed, clWhite);
// aListBoxFontColor: array [Boolean] of TColor = (clInactiveCaptionText, clBlack);
procedure TForm3.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
oldFontColor: TColor;
oldFontName: string;
oldFontS: Byte;
aLBCanvas: TCanvas;
begin
aLBCanvas := TListBox(Control).Canvas;
if odSelected in State then
begin
aLBCanvas.Brush.Color := aListBoxBrushSelectedColor;
aLBCanvas.Font.Color := aListBoxFontSelectedColor;
end
else
begin
aLBCanvas.Brush.Color := aListBoxBrushColor[Odd(Index)];
aLBCanvas.Font.Color := aListBoxFontColor[(Enabled)];
end;
aLBCanvas.FillRect(Rect);
oldFontColor := aLBCanvas.Font.Color;
oldFontS := aLBCanvas.Font.Size;
oldFontName := aLBCanvas.Font.Name;
aLBCanvas.TextOut(Rect.Left + 5, Rect.Top + (Rect.Height div 2) - 5, TListBox(Control).Items[Index]);
if odFocused in State then
begin
aLBCanvas.Brush.Color := TListBox(Control).Color;
aLBCanvas.DrawFocusRect(Rect);
end;
aLBCanvas.Font.Color := oldFontColor;
aLBCanvas.Font.Size := oldFontS;
aLBCanvas.Font.Name := oldFontName;
end;
|
|
Zitat
|