⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 如何控制combo控件下拉框的宽度.txt

📁 以电子书的形式收集了VB一些常见问题解决方法,可以很方便的查找自己需要解决的问题.对一些VB初学者很用.
💻 TXT
字号:
可 以 使 用 CB_SETDROPPEDWIDTH消 息 。 下 面 是 一 个 例 子 : 
    Public Sub SetComboWidth(cboIn As ComboBox) 
    ' Resize the with of the dropdown portion of a combobox to accomodate the longest item 
     
     Dim nCount As Long 
     Dim nNumChars As Long 
     Dim nLongestComboItem As Long 
     Dim nNewDropDownWidth As Long 
     Dim nOldScaleMode As Integer 
     Dim nLongestComboItemIndex As Integer 
     Dim oOldFont As Font 
     
     ' Loop through the cboIn entries, to determine the longest item 
     For nCount = 0 To cboIn.ListCount - 1 
     nNumChars = SendMessage(cboIn.hwnd, CB_GETLBTEXTLEN, nCount, CLng(0)) 
     If nNumChars > nLongestComboItem Then 
     nLongestComboItem = nNumChars 
     nLongestComboItemIndex = nCount 
     End If 
     Next 
     
     ' Save the parent's font and scale mode 
     nOldScaleMode = cboIn.Parent.ScaleMode 
     Set oOldFont = cboIn.Parent.Font 
     
     cboIn.Parent.ScaleMode = vbPixels 
     Set cboIn.Parent.Font = cboIn.Font 
     
     ' Get Width of longest item in pixels 
     nNewDropDownWidth = cboIn.Parent.TextWidth(cboIn.List(nLongestComboItemIndex)) 
     cboIn.Parent.ScaleMode = nOldScaleMode 
     Set cboIn.Parent.Font = oOldFont 
     
     ' Add width of vertical scrollbar 
     If cboIn.ListCount > 8 Then 
     nNewDropDownWidth = nNewDropDownWidth + GetSystemMetrics(SM_CYVSCROLL) + 7 
     Else 
     nNewDropDownWidth = nNewDropDownWidth + 7 
     End If 
     ' Resize the dropdown portion of the cboIn box 
     SendMessage cboIn.hwnd, CB_SETDROPPEDWIDTH, nNewDropDownWidth, CLng(0) 
    End Sub 
<END>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -