I'm creating an on-screen keyboard at the moment to be integrated into an application intended for use on touch-screens. I haven't completed it yet and I'm not necessarily going to post the finished product, but here are the building blocks: a form and a button that will not receive focus. Just note that this behaviour applies to the client area of the form only. If the the user clicks the non-client area, i.e. the title bar and border, then the form will take the focus. This behaviour is just like the in-built Windows OSK.vb.net Code:
''' <summary> ''' A button control that cannot receive focus. ''' </summary> Public Class UnselectableButton Inherits System.Windows.Forms.Button #Region " Constructors " ''' <summary> ''' Initialises a new instance of the <see cref="UnselectableButton"/> class. ''' </summary> Public Sub New() MyBase.New() 'The button cannot receive focus. Me.SetStyle(ControlStyles.Selectable, False) End Sub #End Region 'Constructors #Region " Variables " ''' <summary> ''' Corresponds to the MA_NOACTIVATE window process reply. ''' </summary> Private Shared ReadOnly noActivate As New IntPtr(NativeConstants.MA_NOACTIVATE) #End Region 'Variables #Region " Methods " ''' <summary> ''' Processes Windows messages. ''' </summary> ''' <remarks> ''' Informs Windows not to activate the window when it is clicked with the mouse. Note that this behaviour applies to the client area of the window only. ''' </remarks> Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) MyBase.WndProc(m) If m.Msg = NativeConstants.WM_MOUSEACTIVATE Then 'Tell Windows not to activate the window on a mouse click. m.Result = noActivate End If End Sub Protected Overrides Sub OnClick(ByVal e As System.EventArgs) MyBase.OnClick(e) End Sub #End Region 'Methods End Class




Reply With Quote