Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

Focusrechteck bei selbstgezeichneter Listbox

  Alt 20. Feb 2009, 11:03
Ich zeichne mit folgende,m Code die Inahlte einer Listbox selber:
Delphi-Quellcode:
procedure DrawItems(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
const
  Col2 : array[Boolean] of TColor = (clInactiveCaptionText, clWindowText);
var
  Bmp: TBitmap;
  ItemCaption : string;
  Nachname : string;
  Vorname : string;
  Firma : string;
  Tele1 : string;
  Tele2 : string;

begin
  Nachname := TContact((Control as TListbox).Items.Objects[Index]).Name;
  Vorname := TContact((Control as TListbox).Items.Objects[Index]).Vorname;
  Firma := TContact((Control as TListbox).Items.Objects[Index]).Firma;
  Tele1 := RemoveNonNumberChrs(TContact((Control as TListbox).Items.Objects[Index]).Telefon1);
  Tele2 := RemoveNonNumberChrs(TContact((Control as TListbox).Items.Objects[Index]).Telefon2);

  ItemCaption := Helper.Makecaption(Nachname, Vorname, Firma);
  with (Control as TListbox) do
  begin
    if odSelected in State then
      Canvas.Font.Color := clCaptionText
    else
      Canvas.Font.Color := Col2[(Control as TListbox).Enabled];

    // Grafik
    Bmp := TBitmap.Create;
    try
      Main.frmAdressen.ImageList1.GetBitmap(6, Bmp);
      Canvas.Draw(Rect.Left + 4, Rect.Top + 4, Bmp);
    finally
      Bmp.Free;
    end;

    // Itemcaption
    Canvas.Font.Style := [fsBold];
    Canvas.Font.Size := 12;
    Canvas.Font.Name := 'Arial';
    Canvas.TextOut(Rect.Left + 25, Rect.Top + 3, ItemCaption);
    // SubText
    Canvas.Font.Style := [];
    Canvas.Font.Size := 10;

    Rect.Left := Rect.Left + 10;
    Rect.Top := rect.Top + 2 + 19;
    // nur Telefon1
    if Tele1 <> 'then
    begin
      DrawText(Canvas.Handle, PChar(Tele1), length(Tele1), Rect, DT_LEFT);
    end;
    // nur Telefon2
    if Tele2 <> 'then
    begin
      DrawText(Canvas.Handle, PChar(Tele2), length(Tele2), Rect, DT_LEFT);
    end;
    // beides
    if (Tele1 <> '') and (Tele2 <> '') then
    begin
      DrawText(Canvas.Handle, PChar(Tele1), length(Tele1), Rect, DT_LEFT);
      Rect.Left := Rect.Left + 125;
      DrawText(Canvas.Handle, PChar(Tele2), length(Tele2), Rect, DT_LEFT);
    end;
  end;
end;
Funktioniert soweit auch ganz gut. Es gibt nur einen Schönheitsfehler, wenn ich nacheinander Items anklicke mit der Maus, bleibt der gepunktete Rahmen bei allen Items erhalten. Wie kann ich dafür sorgen, dass der gepunktete Rahmen entfernt wird bei den vorherigen Items?

Im Anhang ein Screenshot. Ich hoffe, man kann erkennen, was ich meine.
Miniaturansicht angehängter Grafiken
adressdbxml_926.jpg  
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat