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

📄 form1.frm

📁 这里有很多很实用的VB编程案例,方便大家学习VB.
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "自动改变列表长度"
   ClientHeight    =   4230
   ClientLeft      =   1140
   ClientTop       =   1515
   ClientWidth     =   3405
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   4230
   ScaleWidth      =   3405
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   720
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   120
      Width           =   1815
   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 Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Public Sub SizeCombo(frm As Form, cbo As ComboBox)
    Dim cbo_left As Integer
    Dim cbo_top As Integer
    Dim cbo_width As Integer
    Dim cbo_height As Integer
    Dim old_scale_mode As Integer

    '改变窗体显示模式。
    old_scale_mode = frm.ScaleMode
    frm.ScaleMode = vbPixels

    '保存下拉列表框初始状态。
    cbo_left = cbo.Left
    cbo_top = cbo.Top
    cbo_width = cbo.Width

    '计算调整的长度。
    cbo_height = frm.ScaleHeight - cbo.Top - 5
    frm.ScaleMode = old_scale_mode

    MoveWindow cbo.hwnd, cbo_left, cbo_top, _
    cbo_width, cbo_height, 1
End Sub


Private Sub Form_Load()
    Dim i As Integer
    '加入列表项。
    For i = 1 To 50
        Combo1.AddItem Format$(i)
    Next i
    Combo1.ListIndex = 0
End Sub


Private Sub Form_Resize()
    ' 当窗体发生变化,改变下拉框长度。
    SizeCombo Me, Combo1
End Sub

⌨️ 快捷键说明

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