[Reference] manage soft Input Panel (SIP)

Source: Internet
Author: User
Http://www.christec.co.nz/blog/archives/42
Manage soft Input Panel (SIP)

One final finishing touch to Windows Mobile applications is the proper handling of the software-based Input Panel (SIP), this can help differentiate your application, and thus your company as one which truely understands the Windows Mobile platform.

The software-based Input Panel (also known as the popup or software keyboard) allows touch-screen enabled devices that do not have a hardware keyboard to simulate keyboard input by using an onscreen keyboard.

The SIP is a common piece of UI, which enables the use of one or more input methods (IMS ). standard input methods include keyboard, transcriber and block recognizer, but additional OEM specific IMS may be encoded on a given device.

This architecture is extendable, and third parties can create their own IMs by implementing a COM object, as outlined in the book prorgraming Microsoft Windows CE, second Edition (see the free sample chapter for step by step instructions ). one interesting third party Input Panel is the smilies Input Panel by Yin-see Tan which is designed to help users enter similies into MSN Messenger.

Tight integration of the SIP within your application typically boils down to handling two scenarios well:

  • Automatically displaying the sip when keyboard focus passes to a control which requires keyboard data entry.
  • Ensuring all controls are accessible when the SIP is visible.

SIP support within the. NET Compact framework
Within the. NET Compact framework the software-based Input Panel is wrapped up by the Microsoft. WindowsCE. Forms. inputpanel class, which is present in the Microsoft. WindowsCE. Forms. dll assembly.

In order to interact with the software-based Input Panel, the user can drop the inputpanel component from the Visual Studio toolbox onto a form. A reference to the Microsoft. windowsCE. forms. DLL assembly will be added automatically to your project.

Most applications utilising the inputpanel component will make use of the following four members of the class.

  • Enabled-A boolean property. If true the SIP is visible (on the screen), if false the SIP is den.
  • Enabledchanged-an event which fires whenever the enabled property changes value.
  • Bounds-a rectangle detailing the amount of screen real estate the current input method occupies.
  • Visibledesktop-a rectangle detailing the maximum size the current screen real estate the form can cover without being partially covered by the SIP.

Automatic sip popup
Within the. NET Compact framework the easiest way to automatically display the Input Panel is to explicitly enable and disable the Input Panel whenever a control which requires keyboard focus is activated.

private TextBox txtUserName; private void Form1_Load(object sender, EventArgs e){txtUserName.GotFocus += txtUserName_GotFocus;txtUserName.LostFocus += txtUserName_LostFocus;} private void txtUserName_GotFocus(object sender, EventArgs e){// Show the input panelinputPanel1.Enabled = true;} private void txtUserName_LostFocus(object sender, EventArgs e){// Hide the input panelinputPanel1.Enabled = false;}

Notice: Usually the event hook up code shown within the form1_load event handler wowould occur within the designer generated code. It is only shown here to aid in understanding how this sample code functions.

Dynamic dialog Layout
Since the SIP is displayed on screen it covers part of your form when visible and potentially makes some of your controls inaccessable. A quality application will alter the layout of its form when the SIP becomes visible to ensure all controls are accessible at all times. there are numerous techniques that can be utilised to achieve this goal.

Technique One:
One approach is to listen to the inputpanel's enabledchanged event. this event will trigger whenever the SIP's visibility changes. within the event handler we can move controls around to ensure that they are visible within the current space available to the form.

private void InputPanel1_EnabledChanged(object sender, EventArgs e){int y; if (inputPanel1.Enabled)// SIP visible - position label just above the area covered by the input panel  y = Height - inputPanel1.Bounds.Height;else// SIP not visible - position label just above bottom of formy = Height; // Calculate the position of the top of the labely = y - lblMessage.Height; lblMessage.Location = new Point(0, y);}

This approach is the most Flexiable, but it can become tricky depending upon the number of controls which need to be moved around. coordinate calculations are never fun, especially when multiple device resolutions etc have to be taken into account.

Technique Two:
Another technique which doesn' t involve explict coordinate calculations is to take advantage of the docking and anchoring functionality present with. NET Compact framework v2.0.

The trick is to dock a control to the bottom of the form, and to resize this control's height to match the current height of the SIP. this has the effect of pushing the rest of the content docked to the bottom of the form to be abve the SIP.

This approach is shown in the following example:

private void InputPanel1_EnabledChanged(object sender, EventArgs e){// Resize the panel docked to the bottom of the form to be// the same height as the SIP. This moves other controls also// docked to the bottom of the form to be above the area covered// by the SIP.SuspendLayout();panelSIP.Visible = inputPanel1.Enabled;panelSIP.Height = inputPanel.Bounds.Height;ResumeLayout();}

This approach can also be extended to exist with larger forms, where the only real solution is to place a vertical scroll bar onto the form. if all the controls are placed onto a panel, you can configure the Panel by setting the following properties:

  • Autoscroll-true
  • Dock-Fill

With these properties set, you will find a vertical scrollbar automatically appears when required (due to the SIP becomming visible ).

An added finishing touch to this technique is to ensure that any controls on the right hand side of the form has the anchor property set to "right ". this ensures that the controls are not obsecured by the vertical scrollbar when it is present.

Selecting input methods
The inputpanel component can also be used to enumerate a list of available input methods, and to determine which one is currently active.

// List the name and class id of each input method// registered on this deviceforeach (InputMethod im in inputPanel1.InputMethods){MessageBox.Show(im.Name, im.Clsid.ToString());} // Display the name of the currently active input methodInputMethod currentIM = inputPanel1.CurrentInputMethod;MessageBox.Show(im.Name, "Current Input Method");

The inputmethod class is a simple key, value pair containing the name of the input method (a string shown in the SIP popup menu), and the matching class ID. class Identifiers are a com specific concept which uniquely identify different types of object, and since the software-based Input Panel architecture is com based, each input method can be uniquly referred to by its CLSID value.

Code sample
A sample project which demonstrates all the techniques discussed in this article is available for download, and shoshould help clarify the behaviour of the inputpanel control.

VB. NET and inputbox ()
Recently a software-based Input Panel related question came up within an online forum I participant in. as part of answering the question I learned of a VB. net function called inputbox. inputbox is a function which provides a basic data entry mechanic, similar to how msgbox displays simple messages to the user.

It turns out that Microsoft's implementation of inputbox does not deal with dynamically moving the OK and cancel buttons around to ensure that they are visible if the software-based Input Panel is visible. it also does not look too nice on VGA resolution devices.

I have written a replacement inputbox implementation which resolves these issues. my new and improved inputbox, including a sample project is available for download. I hope this control is of use to those wising to utilise inputbox within their applications.

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.