Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi ComboBox: Breite der DropDown-Liste ändern (https://www.delphipraxis.net/83933-combobox-breite-der-dropdown-liste-aendern.html)

raiguen 9. Jan 2007 10:07

Re: ComboBox: Breite der DropDown-Liste ändern
 
Moin :-)
Erstmal zum Verständnis:
Code:
Perform(CB_SETDROPPEDWIDTH, DropDownListBreite, 0);
Das Setzen der Breite hat nur dann den gewünschten Erfolg, wenn der Wert von DropDownListBreite größer ist als die Breite (=Width) der Combobox! Mit anderen Worten: ist der Wert von DropDownListBreite kleiner als die Breite der DropDownListe, hat der o.a. Code keine Auswirkung, da die Breite der DropDownListe sich dann standardmäßig der Breite der ComboBox anpasst ;)
Möchte man nun - wie gewünscht - die Breite der DropDownListe dem längsten Eintrag in der Combobox anpassen: (von den Schweizern)
Code:
//--nach dem Füllen der Items in der Combobox
procedure TForm1.BreiteAnpassen(Sender: TObject);
var
  i, DropDownListBreite: Integer;
begin
  DropDownListBreite := 0;
  for i := 0 to Combobox1.Items.Count - 1 do
    if (Form1.Canvas.TextWidth(Combobox1.Items[i]) <> DropDownListBreite) then
       DropDownListBreite := Form1.Canvas.TextWidth((Combobox1.Items[i])) + 20;
  ComboBox1.Perform(CB_SETDROPPEDWIDTH, DropDownListBreite, 0);
end;

Sidorion 9. Jan 2007 10:17

Re: ComboBox: Breite der DropDown-Liste ändern
 
Delphi-Quellcode:
//______________________________________________________________________________
Procedure TDieComboBox.SetListHandle(_hHandle: HWND);
Var
   R:TRect;
  iX:integer;
Begin
   If _hHandle<>ListHandle
  Then Begin
     If _hHandle<>0
    Then Begin
         hListHandle:=_hHandle;
         pDefListProc := Pointer(GetWindowLong(hListHandle, GWL_WNDPROC));
         SetWindowLong(hListHandle, GWL_WNDPROC, Longint(pListInstance));
         Case LBShowState Of
            lbsFullSizeLeft,
            lbsFullSizeRight,
            lbsFullSizeCenter: Begin
          GetWindowRect(ListHandle,R);
               R.Right:=R.Left+CellSize*11+2;
          R.Bottom:=R.Top+CellSize*10+2;
          iX:=0;
          Case LBShowState Of
            lbsFullSizeRight: iX:=Width-(R.Right-R.Left);
            lbsFullSizeCenter: iX:=(Width-(R.Right-R.Left)) DIV 2;
          End;
          MoveWindow (ListHandle,R.Left+iX,R.Top,R.Right - R.Left,
                            R.Bottom - R.Top,TRUE );
            End;
      End;
    End Else Begin
         SetWindowLong(hListHandle, GWL_WNDPROC, Longint(pDefListProc));
       hListHandle:=0;
    End;
  End;
End;
Die beiden Befehle, die Du hier brauchst sind 'GetWindowRect', um die Abmessungen der Liste zu bekommen und 'MoveWindow', um die neue Größe zu setzen. Ich hab den Code aus Faulheit nur aus einem Projekt von mir rauskopiert, aber ich denke, der Sinn wird deutlich.

Sidorion 9. Jan 2007 10:33

Re: ComboBox: Breite der DropDown-Liste ändern
 
Du kannst auch alternativ mit
Delphi-Quellcode:
//______________________________________________________________________________
Procedure TDieComboBox.CreateParams(Var _Params: TCreateParams);
Begin
  Inherited;
  _Params.Style:=_Params.Style or WS_HSCROLL;
End;
der Liste ne horizontale Scrollbar verpassen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:23 Uhr.
Seite 2 von 2     12   

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