怎么把Combobox的下拉列表显示成Checkbox
1个回答
2016-09-01
展开全部
' 在窗体中加入一个CheckedListBox,和一个ComboBox
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With Me.CheckedListBox1
.Visible = False
.Items.Add( "Check it out! ")
.Items.Add( "How about this ")
.Items.Add( "Tis good too! ")
.Height = Me.CheckedListBox1.Items.Count * 18
.CheckOnClick = True
End With
Me.Timer1.Enabled = False
Me.Timer1.Interval = 10
End Sub
Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
Me.ComboBox1.DropDownHeight = 1
With Me.CheckedListBox1
.Top = Me.ComboBox1.Top + Me.ComboBox1.Height
.Left = Me.ComboBox1.Left
.Width = Me.ComboBox1.Width
.Visible = True
End With
End Sub
Private Sub CheckedListBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckedListBox1.MouseLeave
Me.CheckedListBox1.Visible = False
Me.ComboBox1.Text = " "
For i As Int32 = 0 To Me.CheckedListBox1.CheckedItems.Count - 1
Me.ComboBox1.Text &= Me.CheckedListBox1.CheckedItems(i).ToString & ", "
Next
Me.ComboBox1.Text = Me.ComboBox1.Text.TrimEnd( ", ")
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With Me.CheckedListBox1
.Visible = False
.Items.Add( "Check it out! ")
.Items.Add( "How about this ")
.Items.Add( "Tis good too! ")
.Height = Me.CheckedListBox1.Items.Count * 18
.CheckOnClick = True
End With
Me.Timer1.Enabled = False
Me.Timer1.Interval = 10
End Sub
Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
Me.ComboBox1.DropDownHeight = 1
With Me.CheckedListBox1
.Top = Me.ComboBox1.Top + Me.ComboBox1.Height
.Left = Me.ComboBox1.Left
.Width = Me.ComboBox1.Width
.Visible = True
End With
End Sub
Private Sub CheckedListBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckedListBox1.MouseLeave
Me.CheckedListBox1.Visible = False
Me.ComboBox1.Text = " "
For i As Int32 = 0 To Me.CheckedListBox1.CheckedItems.Count - 1
Me.ComboBox1.Text &= Me.CheckedListBox1.CheckedItems(i).ToString & ", "
Next
Me.ComboBox1.Text = Me.ComboBox1.Text.TrimEnd( ", ")
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询