首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Windows Mobile >> Windows Mobile 开发 >> 正文
在smartphone程序中指定textbox控件的输入法
作者:wang8712    文章来源:csdn blog    更新时间:2007-9-25 10:50:54

由于.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里的正在研究中,当我研究出来时,也会贴到这里.谢谢大家!~

相关文章:
没有相关文章
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号