style属性是只读的,一般在设计时才能改变它。动态创建的combo控件的style默认为1,可通过api改变其值Private Const GWL_STYLE = (-16)
Private Const GW_CHILD = 5
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Const SW_HIDE = 0
Const SW_SHOW = 5
Dim WithEvents Combo1 As ComboBoxPrivate Sub Command2_Click()
Set Combo1 = Controls.Add("VB.ComboBox", "Combo1")
Combo1.Visible = True
Combo1.AddItem "1"
Combo1.AddItem "2"
End SubPrivate Sub Command3_Click() '改变值为2
Dim C As Long
C = GetWindow(Combo1.hwnd, GW_CHILD)
Call DestroyWindow(C)
Call SetWindowLong(Combo1.hwnd, GWL_STYLE, GetWindowLong(Combo1.hwnd, GWL_STYLE) + 1)
End Sub