本文适用于在Windows Mobile 2003 for Smartphone平台下使用.net Compact Framework + C# 进行应用开发的人员,由biplip开发人员在dopod 565手机上测试通过。
1、导入API
public class MyForm : System.Windows.Forms.Form
{
..........
public const uint EM_SETINPUTMODE = 0xDE;
public const uint EIM_SPELL = 0;
public const uint EIM_AMBIG = 1;
public const uint EIM_NUMBERS = 2;
[DllImport("coredll.dll")]
public static extern IntPtr GetFocus();
[DllImport("coredll.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Message, uint wParam, uint lParam);
...........
}
2、在组件初始化函数中定义事件处理
private void InitializeComponent()
{
............
this.tbNum.GotFocus += new System.EventHandler(this.tbNum_GotFocus);
...........
}
3、在事件发生时将输入法切换为数字模式
private void tbNum_GotFocus(object sender, System.EventArgs e)
{
.............
IntPtr hWnd;
hWnd = GetFocus();
SendMessage(hWnd, EM_SETINPUTMODE, 0, EIM_NUMBERS);
............
}