📄 用api根据listbox最长项目的宽度来设置滚动条.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "设定适当宽度的水平滚动条"
ClientHeight = 2670
ClientLeft = 60
ClientTop = 345
ClientWidth = 3630
BeginProperty Font
Name = "MS Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 2670
ScaleWidth = 3630
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "设定适当宽度的水平滚动条"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 1
Top = 2040
Width = 3375
End
Begin VB.ListBox List1
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1680
ItemData = "用API根据ListBox最长项目的宽度来设置滚动条.frx":0000
Left = 120
List = "用API根据ListBox最长项目的宽度来设置滚动条.frx":0187
TabIndex = 0
Top = 120
Width = 3375
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
Dim max As Long, f As Font, i As Integer
Me.ScaleMode = vbPixels
Set f = Me.Font
Set Me.Font = List1.Font
With List1
For i = 0 To .ListCount
If Me.TextWidth(.List(i)) > max Then
max = Me.TextWidth(.List(i))
End If
Next
End With
max = max + 10
Set Me.Font = f
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, max, ByVal 0&
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -