Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Items in ComboBox rechtsbündig (https://www.delphipraxis.net/173595-items-combobox-rechtsbuendig.html)

Ykcim 6. Mär 2013 13:21

Items in ComboBox rechtsbündig
 
Hallo Zusammen,

ich möchte, dass die Items in meiner ComboBox und dann bei Auswahl auch der Text rechtsbündig sind. Ich war davon ausgegangen, dass ich das im Objektinspektor wie bei einem Editfeld einstellen kann. Ich finde aber nichts dergleichen...

Könnt Ihr mir weiterhelfen? Das ist doch nun nichts exotisches... :?:

Gruß
Patrick

DeddyH 6. Mär 2013 13:24

AW: Items in ComboBox rechtsbündig
 
Selber zeichnen?

Popov 6. Mär 2013 13:36

AW: Items in ComboBox rechtsbündig
 
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox1.Style := lbOwnerDrawFixed; //das kann man auch im ObjektInspector einstellen
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListbox) do
    Canvas.TextRect(Rect, Rect.Right - Canvas.TextWidth(Items[Index]) - 2, Rect.Top, Items[Index]);
end;
Die -2 ist dafür da, damit ein kleiner Abstand zum rechten Rand besteht.

Natcree 6. Mär 2013 14:35

AW: Items in ComboBox rechtsbündig
 
Oder Direkt für die Combobox...

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
combobox1.style:=csownerdrawfixed;
end;

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as Tcombobox) do
  Canvas.TextRect(Rect, Rect.Right - Canvas.TextWidth(Items[Index]) - 2, Rect.Top, Items[Index]);
end;

DeddyH 6. Mär 2013 14:59

AW: Items in ComboBox rechtsbündig
 
Dann mache ich auch mit:
Delphi-Quellcode:
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
const
  RIGHT_OFFSET = 2;
var
  CBB: TComboBox;
begin
  CBB := Control as TComboBox;
  CBB.Canvas.FillRect(Rect);
  Rect.Right := Rect.Right - RIGHT_OFFSET;
  DrawText(CBB.Canvas.Handle, PChar(CBB.Items[Index]), -1, Rect,
    DT_RIGHT or DT_SINGLELINE);
end;
Damit ist die DropDown-Liste allerdings auch rechtsbündig, sieht IMO ein wenig komisch aus.

Natcree 6. Mär 2013 16:42

AW: Items in ComboBox rechtsbündig
 
lol:lol:

Ykcim 6. Mär 2013 21:00

AW: Items in ComboBox rechtsbündig
 
Hallo Zusammen,

vielen Dank für die Lösungen. Ich muss mich ein bißchen mit beschäftigen, da die TausenderPunkte der Items ein Fehler erzeugen. Da es sich aber um sehr hohe Zahlen handelt, möchte ich die drin haben...

Vielen Dank
Patrick


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:44 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz