C # winform implements a simple virtual keyboard

Source: Internet
Author: User

There are two key technical points:

1. Set the form of the keyboard to the floating toolbar form. You only need to rewrite the createparams of the form so that the form does not obtain the focus,CodeAs follows:

# Region Specify the current form as a floating toolbar form
Public Enum Windowstyles: Uint
{
Ws_overlapped = Zero X 00000000 ,
Ws_popup = Zero X 80000000 ,
Ws_child = Zero X 40000000 ,
Ws_minimize = Zero X 20000000 ,
Ws_visible = Zero X 10000000 ,
Ws_disabled = Zero X 08000000 ,
Ws_clipsiblings = Zero X 04000000 ,
Ws_clipchildren = Zero X 02000000 ,
Ws_maximize = Zero X 01000000 ,
Ws_border = Zero X 00800000 ,
Ws_dlgframe = Zero X 00400000 ,
Ws_vscroll = Zero X 00200000 ,
Ws_hscroll = Zero X 00100000 ,
Ws_sysmenu = Zero X 00080000 ,
Ws_thickframe = Zero X 00040000 ,
Ws_group = Zero X 00020000 ,
Ws_tabstop = Zero X 00010000 ,

ws_minimizebox = 0x00020000 ,
ws_maximizebox = 0x00010000 ,

ws_caption = ws_border | ws_dlgframe,
ws_tiled = ws_overlapped,
ws_iconic = ws_minimize,
ws_sizebox = ws_thickframe,
ws_tiledwindow = ws_overlappedwindow,

Ws_overlappedwindow = ws_overlapped | ws_caption | ws_sysmenu | ws_thickframe | ws_minimizebox | ws_maximizebox,
Ws_popupwindow = ws_popup | ws_border | ws_sysmenu,
Ws_childwindow = ws_child,

// Extended window styles

Ws_ex_dlgmodalframe = Zero X 00000001 ,
Ws_ex_noparentnotify = Zero X 00000004 ,
Ws_ex_topmost = Zero X 00000008 ,
Ws_ex_acceptfiles = Zero X 00000010 ,
Ws_ex_transparent = Zero X 00000020 ,

// # If (winver> = 0x0400)

Ws_ex_mdichild = Zero X 00000040 ,
Ws_ex_toolwindow = Zero X 00000080 ,
Ws_ex_windowedge = Zero X 00000100 ,
Ws_ex_clientedge = Zero X 00000200 ,
Ws_ex_contexthelp = Zero X 00000400 ,

Ws_ex_right = Zero X 00001000 ,
Ws_ex_left = Zero X 00000000 ,
Ws_ex_rtlreading = Zero X 00002000 ,
Ws_ex_ltrreading = Zero X 00000000 ,
Ws_ex_leftscrollbar = Zero X 00004000 ,
Ws_ex_rightscrollbar = Zero X 00000000 ,

ws_ex_controlparent = 0x00010000 ,
ws_ex_staticedge = 0x00020000 ,
ws_ex_appwindow = 0x00040000 ,

Ws_ex_overlappedwindow = (ws_ex_javaswedge | ws_ex_clientedge ),
Ws_ex_palettewindow = (ws_ex_shortwedge | ws_ex_toolwindow | ws_ex_topmost ),

//# Endif/* winver> = 0x0400 */

//# If (win32winnt> = 0x0500)

Ws_ex_layered =Zero X 00080000,

//# Endif/* win32winnt> = 0x0500 */

// # If (winver> = 0x0500)

Ws_ex_noinheritlayout = Zero X 00100000 , // Disable inheritence of processing ing by children
Ws_ex_layoutrtl = Zero X 00400000 , // Right to left grouping ing

//# Endif/* winver> = 0x0500 */

//# If (win32winnt> = 0x0500)

Ws_ex_composited =Zero X 02000000,
Ws_ex_noactivate =Zero X 08000000

// # Endif/* win32winnt> = 0x0500 */

}
Protected Override Createparams
{
Get
{
Createparams ret = Base . Createparams;
Ret. Style = ( Int ) Windowstyles. ws_thickframe | ( Int ) Windowstyles. ws_child;
Ret. exstyle | = ( Int ) Windowstyles. ws_ex_noactivate | ( Int ) Windowstyles. ws_ex_toolwindow;
Ret. x = This . Location. X;
Ret. Y = This . Location. Y;
Return RET;
}
}

# Endregion 

2. Use the sendkeys method to send the key to the applicationProgram. See how to use sendkeys.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.