unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TSuche =
record
Text: AnsiString;
ItemPos: integer;
StrPos: integer;
end;
type
TForm6 =
class(TForm)
ListBoxHilfeAllgemein: TListBox;
LaHilfeInformantionen: TLabel;
ListBoxHilfeAnwendungen: TListBox;
procedure ListBoxHilfeAllgemeinDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure ListBoxHilfeAnwendungenDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure FormCreate(Sender: TObject);
private
Suche: TSuche;
public
{ Public-Deklarationen }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
procedure TForm6.ListBoxHilfeAllgemeinDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
ListText, SelText: AnsiString;
begin
with (Control
as TListBox).Canvas
do
begin
if not (odFocused
in State)
then
begin
if Index = Suche.ItemPos
then // markiertes Item
begin
Brush.Color:= graphics.clYellow;
//clRed;//graphics.clHighlight;
FillRect(Rect);
Font.Color:= graphics.clBlack;
ListText:= (Control
as TListBox).Items[
Index];
TextOut(Rect.Left + 2, Rect.Top, ListText);
Font.Color:= graphics.clRed;
SelText:= Copy(ListText, Suche.StrPos, length(Suche.Text));
TextOut(Rect.Left + 2+ TextWidth(Copy(ListText, 1, Suche.StrPos- 1)), Rect.Top, SelText);
end else
begin
Brush.Color := (Control
as TListBox).Color;
Font.Color:= graphics.clBlack;
FillRect(Rect);
TextOut(Rect.Left + 2, Rect.Top, (Control
as TListBox).Items[
Index]);
end;
end;
end;
end;
procedure TForm6.ListBoxHilfeAnwendungenDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
ListText, SelText: AnsiString;
begin
with (Control
as TListBox).Canvas
do
begin
if not (odFocused
in State)
then
begin
if Index = Suche.ItemPos
then // markiertes Item
begin
Brush.Color:= graphics.clYellow;
//clRed;//graphics.clHighlight;
FillRect(Rect);
Font.Color:= graphics.clBlack;
ListText:= (Control
as TListBox).Items[
Index];
TextOut(Rect.Left + 2, Rect.Top, ListText);
Font.Color:= graphics.clRed;
SelText:= Copy(ListText, Suche.StrPos, length(Suche.Text));
TextOut(Rect.Left + 2+ TextWidth(Copy(ListText, 1, Suche.StrPos- 1)), Rect.Top, SelText);
end else
begin
Brush.Color := (Control
as TListBox).Color;
Font.Color:= graphics.clBlack;
FillRect(Rect);
TextOut(Rect.Left + 2, Rect.Top, (Control
as TListBox).Items[
Index]);
end;
end;
end;
end;
procedure TForm6.FormCreate(Sender: TObject);
begin
begin
ZeroMemory(@Suche, SizeOf(TSuche));
Suche.ItemPos:= -1;
Form6.ListBoxHilfeAllgemein.Style := lbOwnerDrawFixed;
Form6.ListBoxHilfeAnwendungen.Style := lbOwnerDrawFixed;
end;
end;
end.