vb里面通过代码弄出来的combo怎么改变style

 我来答
匿名用户
2013-12-18
展开全部
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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式