Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#7

AW: Combobox: im Onselect Text ändern geht nicht

  Alt 16. Mai 2015, 00:38
Eine Möglichkeit, um beim Beispiel zu bleiben:
Delphi-Quellcode:
procedure GetAllFiles(Path: String; List: TStrings);
var
  Search: TSearchRec;
begin
  if FindFirst(Path + '*.*', faAnyFile, Search) = 0 then
  repeat
    List.Add(Path + Search.Name);
  until FindNext(Search) <> 0;
  FindClose(Search);
end;

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  TopDiff: Integer; //zentriert Text vertikal
  FileName: String;
begin
  with (Control as TComboBox) do
  begin
    if DroppedDown then //<<<<<<<<<<<<<<
      FileName := Items[Index]
    else
      FileName := ExtractFileName(Items[Index]);

    TopDiff := (ItemHeight div 2) - (Canvas.TextHeight(Items[Index]) div 2);

    Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + TopDiff, FileName);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ComboBox1.Clear;
  ComboBox1.Style := csOwnerDrawFixed;
  GetAllFiles('C:\Windows\', ComboBox1.Items);
end;
Anhängig ob Dropdown-Liste unten ist oder nicht, wird entweder das eine oder das andere gezeigt.

Hier jetzt ein Beispiel mit ComboBox.
  Mit Zitat antworten Zitat