06-10-12, 10:31 PM
كاتب الموضوع : BADRMEDIA
أحد الأعضاء المكرمين طلب أنه عند الضغط على DropDown لأداة ComboBox
يكون عرض العناصر المعروضة على أكبر عنصر موجود
ولحل ذلك
نضع هذه الاجراءية
كود :
Sub ComboBox_WidthComboBox(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim sendCombobox As ComboBox = sender
Dim wid As Integer = sendCombobox.DropDownWidth
Dim Graf As Graphics = sendCombobox.CreateGraphics
Dim Fonta As Font = sendCombobox.Font
Dim VerticalComboBox As Integer = IIf((sendCombobox.Items.Count > sendCombobox.MaxDropDownItems), SystemInformation.VerticalScrollBarWidth, 0)
Dim newWid As Integer
For Each str As String In DirectCast(sender, ComboBox).Items
newWid = CInt(Graf.MeasureString(str, Font).Width) + VerticalComboBox
If wid < newWid Then
wid = newWid
End If
Next
sendCombobox.DropDownWidth = Width
End Subنرسل handler الكومبو المطلوب لهذه الاجراءية
هكذا
كود :
Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
AddHandler ComboBox1.DropDown, AddressOf ComboBox_WidthComboBox
End Subوالله ولى التوفيق