Forumlar
Yeni Mesajlar
CerezExtra
EĞLENCE ↓
Şans Kurabiyesi
Renk Falınız
ÇerezRADYO
Sevgiliye Özel
ÇerezDERGİ
Hızlı Okuma Testleri
Pratik Çözümler
Yeniler
Yeni Mesajlar
Yeni ürünler
Yeni kaynaklar
Son Aktiviteler
İndir
En son incelemeler
Dükkan
Giriş
Kayıt
Yeniler
Yeni Mesajlar
Menu
Giriş
Kayıt
Uygulamayı yükle
Yükle
Forumlar
Bilgisayar & Cep & Teknoloji
Programlama Dilleri
Delphi İle Başlangıç
ComboBox açılır pencere genişliğini değiştirmek
JavaScript devre dışı bırakıldı. Daha iyi bir deneyim için, devam etmeden önce lütfen tarayıcınızda JavaScript'i etkinleştirin.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Konuya cevap yaz
Mesaj
<blockquote data-quote="YoRuMSuZ" data-source="post: 824871" data-attributes="member: 1"><p>Eğer form üzerinde bulunan tüm Combobox veya DBComboBox açılır pencere genişliğini otomatik olarak ayarlamak isterseniz şu kodlar işinizi görecektir...</p><p></p><p>Tüm sayfa kodu...</p><p>[CODE]</p><p>unit Unit1;</p><p></p><p>interface</p><p></p><p>uses</p><p> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,</p><p> Dialogs, StdCtrls;</p><p></p><p>type</p><p> TForm1 = class(TForm)</p><p> ComboBox1: TComboBox;</p><p> ComboBox2: TComboBox;</p><p> ComboBox3: TComboBox;</p><p> private</p><p> { Private declarations }</p><p> public</p><p> { Public declarations }</p><p> end;</p><p></p><p>var</p><p> Form1: TForm1;</p><p> cwpHandle: THandle;</p><p> SaveRight:Integer;</p><p></p><p>implementation</p><p></p><p>{$R *.dfm}</p><p></p><p>procedure AutoSetComboxDropDownWidth( AComboBox: TComboBox );</p><p>var</p><p> i: Integer;</p><p> MaxWidth: Integer;</p><p> CurWidth: Integer;</p><p> TempSize: SIZE;</p><p> TempHDC: HDC;</p><p> SaveFont: HFont;</p><p>begin</p><p> MaxWidth := AComboBox.Width; //(GetSystemMetrics(SM_CXVSCROLL)*2);</p><p> TempHDC := GetDC(0);</p><p> try</p><p> for i := 0 to AComboBox.Items.Count-1 do</p><p> begin</p><p> SaveFont := SelectObject( TempHDC, AComboBox.Font.Handle );</p><p> Windows.GetTextExtentPoint32( TempHDC, PChar(AComboBox.Items[i]),</p><p> Length(AComboBox.Items[i]),</p><p> TempSize );</p><p> SelectObject( TempHDC, SaveFont );</p><p></p><p> //if scrollbar needed.</p><p> if AComboBox.Items.Count>AComboBox.DropDownCount then</p><p> //The 8 seems to provide a centering effect between left and right.</p><p> CurWidth := TempSize.cx + (GetSystemMetrics(SM_CXVSCROLL)+8)</p><p> else</p><p> CurWidth := TempSize.cx+8;</p><p> if CurWidth>MaxWidth then</p><p> MaxWidth := CurWidth;</p><p> end;</p><p> finally</p><p> ReleaseDC(0, TempHDC );</p><p> end;</p><p> SaveRight := AComboBox.ClientOrigin.X + AComboBox.Width;</p><p> AComboBox.Perform( CB_SETDROPPEDWIDTH, MaxWidth, 0 );</p><p>end;</p><p></p><p>procedure MoveDropDownListIfNecessary( AComboBoxListHandle: LongInt );</p><p>var</p><p> R: TRect;</p><p>begin</p><p> GetWindowRect( AComboBoxListHandle, R );</p><p></p><p> if R.Right>=Screen.Width then</p><p> begin</p><p> MoveWindow( AComboBoxListHandle, SaveRight-(R.Right-R.Left)-1, R.Top,</p><p> R.Right-R.Left, R.Bottom-R.Top, True );</p><p> end;</p><p>end;</p><p></p><p>function HookCallbackFunction(nCode: Integer; wParam: LongInt;</p><p>lParam: LongInt): Integer; stdcall;</p><p>var</p><p> wNotifyCode: Integer;</p><p> Control: TWinControl;</p><p> ListHandle: LongInt;</p><p>begin</p><p> Result := CallNextHookEx(cwpHandle,nCode,wParam,lParam);</p><p> // Don't do anything when program is closing</p><p> if (Application.Terminated) or (nCode<0) then</p><p> Exit;</p><p></p><p> if nCode=HC_ACTION then</p><p> begin</p><p> if PCWPStruct(LParam)^.message = WM_COMMAND then</p><p> begin</p><p> wNotifyCode := HIWORD(PCWPStruct(LParam)^.wParam);</p><p></p><p> if wNotifyCode = CBN_DROPDOWN then</p><p> begin</p><p> Control := FindControl( PCWPStruct(LParam)^.lParam );</p><p></p><p> if (Control<>nil) and (Control is TComboBox) then</p><p> AutoSetComboxDropDownWidth( TComboBox( Control ) );</p><p> end;</p><p> end</p><p> else if PCWPStruct(LParam)^.message = WM_CTLCOLORLISTBOX then</p><p> begin</p><p> ListHandle := PCWPStruct(LParam)^.lParam;</p><p> MoveDropDownListIfNecessary( ListHandle );</p><p> end;</p><p> end;</p><p>end;</p><p></p><p>initialization</p><p> cwpHandle := SetWindowsHookEx( WH_CALLWNDPROC, @HookCallbackFunction, 0, MainThreadID );</p><p></p><p>finalization</p><p> if cwpHandle <> 0 then</p><p> UnhookWindowsHookEx( cwpHandle );</p><p></p><p>end.</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="YoRuMSuZ, post: 824871, member: 1"] Eğer form üzerinde bulunan tüm Combobox veya DBComboBox açılır pencere genişliğini otomatik olarak ayarlamak isterseniz şu kodlar işinizi görecektir... Tüm sayfa kodu... [CODE] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ComboBox1: TComboBox; ComboBox2: TComboBox; ComboBox3: TComboBox; private { Private declarations } public { Public declarations } end; var Form1: TForm1; cwpHandle: THandle; SaveRight:Integer; implementation {$R *.dfm} procedure AutoSetComboxDropDownWidth( AComboBox: TComboBox ); var i: Integer; MaxWidth: Integer; CurWidth: Integer; TempSize: SIZE; TempHDC: HDC; SaveFont: HFont; begin MaxWidth := AComboBox.Width; //(GetSystemMetrics(SM_CXVSCROLL)*2); TempHDC := GetDC(0); try for i := 0 to AComboBox.Items.Count-1 do begin SaveFont := SelectObject( TempHDC, AComboBox.Font.Handle ); Windows.GetTextExtentPoint32( TempHDC, PChar(AComboBox.Items[i]), Length(AComboBox.Items[i]), TempSize ); SelectObject( TempHDC, SaveFont ); //if scrollbar needed. if AComboBox.Items.Count>AComboBox.DropDownCount then //The 8 seems to provide a centering effect between left and right. CurWidth := TempSize.cx + (GetSystemMetrics(SM_CXVSCROLL)+8) else CurWidth := TempSize.cx+8; if CurWidth>MaxWidth then MaxWidth := CurWidth; end; finally ReleaseDC(0, TempHDC ); end; SaveRight := AComboBox.ClientOrigin.X + AComboBox.Width; AComboBox.Perform( CB_SETDROPPEDWIDTH, MaxWidth, 0 ); end; procedure MoveDropDownListIfNecessary( AComboBoxListHandle: LongInt ); var R: TRect; begin GetWindowRect( AComboBoxListHandle, R ); if R.Right>=Screen.Width then begin MoveWindow( AComboBoxListHandle, SaveRight-(R.Right-R.Left)-1, R.Top, R.Right-R.Left, R.Bottom-R.Top, True ); end; end; function HookCallbackFunction(nCode: Integer; wParam: LongInt; lParam: LongInt): Integer; stdcall; var wNotifyCode: Integer; Control: TWinControl; ListHandle: LongInt; begin Result := CallNextHookEx(cwpHandle,nCode,wParam,lParam); // Don't do anything when program is closing if (Application.Terminated) or (nCode<0) then Exit; if nCode=HC_ACTION then begin if PCWPStruct(LParam)^.message = WM_COMMAND then begin wNotifyCode := HIWORD(PCWPStruct(LParam)^.wParam); if wNotifyCode = CBN_DROPDOWN then begin Control := FindControl( PCWPStruct(LParam)^.lParam ); if (Control<>nil) and (Control is TComboBox) then AutoSetComboxDropDownWidth( TComboBox( Control ) ); end; end else if PCWPStruct(LParam)^.message = WM_CTLCOLORLISTBOX then begin ListHandle := PCWPStruct(LParam)^.lParam; MoveDropDownListIfNecessary( ListHandle ); end; end; end; initialization cwpHandle := SetWindowsHookEx( WH_CALLWNDPROC, @HookCallbackFunction, 0, MainThreadID ); finalization if cwpHandle <> 0 then UnhookWindowsHookEx( cwpHandle ); end. [/CODE] [/QUOTE]
Alıntıları ekle...
İsim
Spam kontrolü
Sarı kırmızı renkleri ile ünlü futbol takımımız?
Cevapla
Forumlar
Bilgisayar & Cep & Teknoloji
Programlama Dilleri
Delphi İle Başlangıç
ComboBox açılır pencere genişliğini değiştirmek
Top