继承这个combobox,做个自定义控件,定义一下属性,比如isReadOnly
Private iniDropDownStyle As ComboBoxStyle = Me.DropDownStyle
Private iniBackColor As System.Drawing.Color = Me.BackColor
Private isReadOnly As Boolean = False
Public Property [ReadOnly]() As Boolean
Get
Return isReadOnly
End Get
Set(ByVal Value As Boolean)
isReadOnly = Value
If Value = True Then
Me.DropDownStyle = ComboBoxStyle.Simple
Me.BackColor = System.Drawing.SystemColors.Control
Else
Me.DropDownStyle = iniDropDownStyle
Me.BackColor = iniBackColor
End If
End Set
End Property
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
e.Handled = Me.ReadOnly
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
If Me.ReadOnly = True Then
If e.Button = MouseButtons.Right Then
Me.ContextMenu = New ContextMenu
End If
End If
End Sub