Extending the Combo Box Control

tsy
04-06-2006, 02:05 AM
The Combo Box does not have a read only property... thus i have created one for it and have cancelled the keypress event but i dont know how to cancel the mouse click event. My code is below, can someone please help me out.

Public Class ReadOnlyComboBox
Inherits System.Windows.Forms.ComboBox
Private _readOnly As Boolean

Public Sub New()
MyBase.New()
_readOnly = False
End Sub

Public Property ReadOnlyCombo() As Boolean
Get
Return _readOnly
End Get
Set(ByVal value As Boolean)
_readOnly = value
End Set
End Property

Private Sub ReadOnlyKeyHandler(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If _readOnly Then
e.Handled = True
End If
End Sub
Private Sub ReadOnlyMouseHandler(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
If _readOnly Then
'how do i cancel this event
End If
End Sub
End Class

jo0ls
04-06-2006, 05:27 AM
I did something a while ago to do that: http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=2659

Or you could disable the control with an api call:
<DllImport("user32.dll", EntryPoint:="EnableWindow")> _
Private Shared Function EnableWindow(ByVal handle As IntPtr, ByVal bEnable As Boolean) As UInteger
End Function

e.g. EnableWindow(combo1.handle, false)

tsy
04-06-2006, 09:19 PM
I tried your link but Planet Source Code says its no longer available.

The problem with disabling the combo is that it gets that horrible grey out colour.

Thanks for trying.

jo0ls
04-07-2006, 02:50 AM
It's attached...

tsy
04-09-2006, 07:42 PM
Hey thanks, thats awesome, just what i was looking for... most impressed.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum