Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Delphi Combobox mittig ausrichten (https://www.delphipraxis.net/173551-combobox-mittig-ausrichten.html)

Naka1985 2. Mär 2013 19:45

Combobox mittig ausrichten
 
Guten Tag,

folgende Ausgangslage:

Ich habe ein normales Formular mit einer StatusBar und einem Panel.
Die Statusbar ist nach unten ausgerichtet und das Panel hat die Eigenschaft "Einstiegspanel.Align := alclient;"

Nun möchte ich auf dem Panel eine Combobox mittig ausrichten. Hier habe ich jedoch Probleme mit der Höhe bzw. mit dem "top-Attribut".

Ich habe folgenden Quellcode:

Combobox1.top := Trunc ((Trunc (HauptForm.height) - Trunc (Statusbar1.height))/2) - Trunc (Trunc(Combobox1.height)/2);

Ich gebe alle ermittelten Werte mittels showmessage aus und komme rechnerisch auch auf das gewünschte Ergebnis. Wenn ich nun aber (pedantisch wie ich bin) Maß nehme mit meinem Linial kommt es nicht mehr hin.

Ich bin echt am verzweifeln

Könnt Ihr mir helfen?

Danke und Gruß

NaKa

Dalai 2. Mär 2013 19:48

AW: Combobox mittig ausrichten
 
HauptForm.ClientHeight statt HauptForm.Height sollte dir weiterhelfen.

MfG Dalai

Naka1985 2. Mär 2013 19:57

AW: Combobox mittig ausrichten
 
Perfekt! Danke Dir!

Magst Du mir bitte noch den Unterschied erklären?

Danke

Naka1985 2. Mär 2013 20:01

AW: Combobox mittig ausrichten
 
danke hat sich doch erledigt. Ich fauler Sack hab doch mal google bedient :-)

hier noch bei Interesse für andere:

Zitat:

Height is the total height of the form (including titlebar height, main menu height, window borders, etc). ClientHeight is the height of the client-area of the form. The height can vary between systems depending on size of font used for titlebar text, menu text, type of theme used, etc, so setting a form's height to a specific integer gives a different view on different systems.

To roll up a form to its minimum height, set ClientHeight to 0. (You might want to store the old ClientHeight to an integer variable first, so you can restore the form to the same height when the user wants to 'unroll' it.)

Same things apply to Width/ClientWidth, or course, but there's usually only a few pixels' difference between them, and not much system variation.

Hope that helps.

Rob.

Volker Z. 3. Mär 2013 01:56

AW: Combobox mittig ausrichten
 
Hallo,

nachdem nun offenbar klar ist was der Unterschied zwischen Form.Height und Form.ClientHeight ist, stellen wir uns nun die Frage braucht es das alles, um eine Combobox (horizontal) mittig auf einem Panel auszurichten, dabei mehrfach einen Integer mittels Trunc in ein Int64 zu konvertieren? Nein, nicht wirklich. Ein einfaches
Delphi-Quellcode:
procedure TForm1.Panel1Resize(Sender: TObject);
begin
  ComboBox1.Top := Panel1.Height div 2 - ComboBox1.Height div 2
end;
reicht, um die Combobox horizontal auszurichten (auch dann, wenn mal Panel1.Align <> alClient ist, kein Statusbar zur Verfügung steht o. ä.!). Der ein oder andere Pixel Unterschied ist dann dem div geschuldet.

Der Vollständigkeit halber: Zentriert auf dem Panel liegt die Combobox mit:
Delphi-Quellcode:
procedure TForm1.Panel1Resize(Sender: TObject);
begin
  ComboBox1.Left := Panel1.Width div 2 - ComboBox1.Width div 2;
  ComboBox1.Top := Panel1.Height div 2 - ComboBox1.Height div 2
end;
Gruß

DonManfred 4. Mär 2013 05:49

AW: Combobox mittig ausrichten
 
Zitat:

Zitat von Volker Z. (Beitrag 1205754)
Ein einfaches
Delphi-Quellcode:
procedure TForm1.Panel1Resize(Sender: TObject);
begin
  ComboBox1.Top := Panel1.Height div 2 - ComboBox1.Height div 2
end;
reicht, um die Combobox horizontal auszurichten

um die Combobox VERTIKAL auszurichten...


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:17 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