如何在smartphone程序中指定textbox控件的输入法
2006-01-16 18:31
393 查看
由于.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里的正在研究中,当我研究出来时,也会贴到这里.谢谢大家!~
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里的正在研究中,当我研究出来时,也会贴到这里.谢谢大家!~
相关文章推荐
- 在smartphone程序中指定textbox控件的输入法
- Asp.net如何验证TextBox控件只输入数字(五种情况分析)转帖
- java程序读取资源文件时路径如何指定
- c/s程序版本自动升级的问题,如何判断client端版本号是否最新,然后从指定ftp服务器down
- 如何在wince控制面板增加一个响应指定程序的图标
- 如何实现程序调用系统邮件,发送app中抓取的xml图片和内容到指定的邮箱
- .NET C# 如何将光标置于 TextBox 控件中的文本的开头或末尾或当前位置
- MFC程序中如何获取控件在客户区的坐标?
- 如何在Asp.Net下遍历指定页面上的所有控件
- 关于Android输入法遮挡控件处理方法!!!!!(可以指定控件,使其在输入法之上)
- Delphi中如何控制其他程序窗体上的窗口控件
- C# 如何判断指定文件是否正被其它程序使用
- MFC中如何将焦点设置到指定控件上
- iOS中如何让TextView和TextField控件支持return键收起输入法
- winform有一个combobox和一个textbox控件,如何进行动态绑定,使得combobox中的数据改变时,textbox中的数据也随之改变?
- 如何在ASP.NET下遍历指定页面上所有控件
- Flex中如何在Tree控件中指定一个自定义的label函数使其返回的标签名字为叶项目的名称的例子
- linux下可执行程序如何定位共享库文件以及如何让系统找到用户指定的库 .
- 如何控制其他程序窗体上的窗口控件:中
- 如何调用Symbian的输入法控件