Results 1 to 19 of 19

Thread: Building Blocks for an On-screen Keyboard

Threaded View

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Building Blocks for an On-screen Keyboard

    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:
    1. ''' <summary>
    2. ''' A button control that cannot receive focus.
    3. ''' </summary>
    4. Public Class UnselectableButton
    5.     Inherits System.Windows.Forms.Button
    6.  
    7. #Region " Constructors "
    8.  
    9.     ''' <summary>
    10.     ''' Initialises a new instance of the <see cref="UnselectableButton"/> class.
    11.     ''' </summary>
    12.     Public Sub New()
    13.         MyBase.New()
    14.  
    15.         'The button cannot receive focus.
    16.         Me.SetStyle(ControlStyles.Selectable, False)
    17.     End Sub
    18.  
    19. #End Region 'Constructors
    20.  
    21. #Region " Variables "
    22.  
    23.     ''' <summary>
    24.     ''' Corresponds to the MA_NOACTIVATE window process reply.
    25.     ''' </summary>
    26.     Private Shared ReadOnly noActivate As New IntPtr(NativeConstants.MA_NOACTIVATE)
    27.  
    28. #End Region 'Variables
    29.  
    30. #Region " Methods "
    31.  
    32.     ''' <summary>
    33.     ''' Processes Windows messages.
    34.     ''' </summary>
    35.     ''' <remarks>
    36.     ''' 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.
    37.     ''' </remarks>
    38.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    39.         MyBase.WndProc(m)
    40.  
    41.         If m.Msg = NativeConstants.WM_MOUSEACTIVATE Then
    42.             'Tell Windows not to activate the window on a mouse click.
    43.             m.Result = noActivate
    44.         End If
    45.     End Sub
    46.  
    47.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    48.         MyBase.OnClick(e)
    49.     End Sub
    50.  
    51. #End Region 'Methods
    52.  
    53. End Class
    Last edited by jmcilhinney; Oct 9th, 2007 at 03:34 AM. Reason: Removed buggy form code. See post #3 for final code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width