Jump to content

Input Mode


Guest alhabibam

Recommended Posts

Guest alhabibam

Hi all,

Does anyone know how to change the input mode of the mobile (Alphapet --> Numeric) for a specific text field? I wnat to create a text field that should accept only numbers.

Thanks.

Link to comment
Share on other sites

Guest mgama
Hi all,

Does anyone know how to change the input mode of the mobile (Alphapet --> Numeric) for a specific text field? I wnat to create a text field that should accept only numbers.

Thanks.

<{POST_SNAPBACK}>

You can read through OpennetCF to find out how they do it. Search for SetInputMode.

Link to comment
Share on other sites

Guest vman69

Hopefully the following code will help you out. I use it in some of the apps I am writing and it works well for me.

using System;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace SmartAustralianPropertyFeeCalculator

{

public enum InputMode : ushort

{

Spell = 0,

T9 = 1,

Numeric = 2,

Text = 3,

};

///

/// This class will facilitate the ability to

/// change the input type for a field.

/// The standard are:

/// T9

/// Numeric

/// Text

///

public class InputChanger

{

[DllImport("coredll",EntryPoint="GetCapture")]

static extern IntPtr GetCapture();

[DllImport("coredll",EntryPoint="GetWindow")]

static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);

[DllImport("coredll",EntryPoint="SendMessage")]

static extern IntPtr SendMessage(IntPtr hWnd, ushort msg, ushort wParam, ushort lParam);

///

/// Set the input mode for a control that is passed.

///

/// The control whose input method you'd like to change

/// The input mode you'd like to change to

public static void SetInputMode(Control ctrl, InputMode mode)

{

int GW_CHILD = 5;

ushort EM_SETINPUTMODE = 222;

//Get the handle for the control

ctrl.Capture = true;

IntPtr h = GetCapture();

ctrl.Capture = false;

//Get the child window for the control

IntPtr hWndEditBox = GetWindow(h, GW_CHILD);

//Set the input mode

SendMessage(hWndEditBox, EM_SETINPUTMODE, 0, (ushort)mode);

}

}

}

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.