![]() |
Re: ComboBox: Breite der DropDown-Liste ändern
Moin :-)
Erstmal zum Verständnis:
Code:
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 ;)
Perform(CB_SETDROPPEDWIDTH, DropDownListBreite, 0);
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; |
Re: ComboBox: Breite der DropDown-Liste ändern
Delphi-Quellcode:
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.
//______________________________________________________________________________
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; |
Re: ComboBox: Breite der DropDown-Liste ändern
Du kannst auch alternativ mit
Delphi-Quellcode:
der Liste ne horizontale Scrollbar verpassen.
//______________________________________________________________________________
Procedure TDieComboBox.CreateParams(Var _Params: TCreateParams); Begin Inherited; _Params.Style:=_Params.Style or WS_HSCROLL; End; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:23 Uhr. |
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