如何在smartphone程序中指定textbox控件的输入法

由于.netcf里TextBox不像VC++中一样可以指定number的style,所以我们借助API来实现首先,定义一个类,来Pinvoke Win32 API

public class Win32Pinvoke

{

 public enum InputMode { Spell = 0, T9 = 1, Numbers = 2, Text = 3 }

// Constants required for interop

const int GW_CHILD = 5;

const uint EM_SETINPUTMODE = 0x00DE;

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

private static extern IntPtr GetCapture();

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

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

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

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

public static void SetInputMode(Control ctrl, InputMode mode)

{

// Get the handle for the current control

 ctrl.Capture = true;

IntPtr h = GetCapture();

ctrl.Capture = false; /

/ Get the child window for the control

IntPtr hEditbox = GetWindow(h, GW_CHILD);

// Set the input mode SendMessage(hEditbox, EM_SETINPUTMODE, 0, (uint)mode);

}

}

其次, 在textbox的GOTFOCUS消息中实现:

private void textBox_GotFocus(object sender, System.EventArgs e)

{

Win32Pinvoke.SetInputMode(this.textBox,Win32Pinvoke.InputMode.Numbers);

 }

注:: 本方法只能应用于smartphone中,对pocket pc不起作用. Pocket pc里的正在研究中,当我研究出来时,也会贴到这里.谢谢大家!~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值