WinForm里如何给文本框添加软键盘

SallyAngela6 2011-08-02 10:45:11
WinForm里如何给文本框添加软键盘,有一个用户名窗体,文本框需要输入用户名,需要弹出软键盘,在软键盘里输入,输入内容会在文本框显示出来,这个该怎么实现呢?摆脱大家了
...全文
772 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
isjoe 2011-08-02
  • 打赏
  • 举报
回复
调用系统自带的软键盘:osk.exe
灵雨飘零 2011-08-02
  • 打赏
  • 举报
回复
using System;  using System.Collections.Generic;  using System.ComponentModel;  using System.Data;  using System.Drawing;  using System.Text;  using System.Windows.Forms;  using System.Runtime.InteropServices;   namespace InputLanguageSwitch  {  /// <summary> /// 获取系统所有的输入法,并可以程序改变当前输入法;打开关闭软键盘。  /// 程序:房客  /// QQ:83849123  /// Blog:http://www.cnblogs.com/sxlfybb  /// </summary> public partial class Form1 : Form  {  public Form1()  {  InitializeComponent();  this.InputLanguageChanged += new InputLanguageChangedEventHandler(Form1_InputLanguageChanged);  }   void Form1_InputLanguageChanged(object sender, InputLanguageChangedEventArgs e)  {  //throw new Exception("The method or operation is not implemented.");  for( int i=0;i<comboBox1.Items.Count;i++)  {  if (InputLanguage.CurrentInputLanguage.LayoutName == comboBox1.Items[i].ToString())  {  comboBox1.SelectedIndex = i;  }   }  }   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)  {  string strTemp = comboBox1.Items[comboBox1.SelectedIndex].ToString();  InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;  for (int i = 0; i < collects.Count; i++)  {  if (collects[i].LayoutName == strTemp)  InputLanguage.CurrentInputLanguage = collects[i];  }   }   private void Form1_Load(object sender, EventArgs e)  {  InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;  for (int i = 0; i < collects.Count; i++)  {  comboBox1.Items.Add(collects[i].LayoutName);  }  comboBox1.SelectedIndex = collects.IndexOf(InputLanguage.CurrentInputLanguage);  }   private void button1_Click(object sender, EventArgs e)  {  this.textBox1.Focus();  IntPtr hwndInput = ImmGetContext(this.Handle);  IntPtr dw1 = IntPtr.Zero;  IntPtr dw2 = IntPtr.Zero;  bool isSuccess = ImmGetConversionStatus(hwndInput, ref dw1, ref dw2);  if (isSuccess)  {  int intTemp = dw1.ToInt32() & IME_CMODE_SOFTKBD;  if (intTemp > 0)  dw1 = (IntPtr)(dw1.ToInt32() ^ IME_CMODE_SOFTKBD);  else  dw1 = (IntPtr)(dw1.ToInt32() IME_CMODE_SOFTKBD);  }  isSuccess = ImmSetConversionStatus(hwndInput, dw1, dw2);  ImmReleaseContext(this.Handle, hwndInput);  }   public const int IME_CMODE_SOFTKBD = 0x80;   [DllImport("imm32.dll", EntryPoint = "ImmGetContext")]  public static extern IntPtr ImmGetContext(  IntPtr hwnd  );  [DllImport("imm32.dll", EntryPoint = "ImmGetConversionStatus")]  public static extern bool ImmGetConversionStatus(  IntPtr himc,  ref IntPtr lpdw,  ref IntPtr lpdw2  );  [DllImport("imm32.dll", EntryPoint = "ImmSetConversionStatus")]  public static extern bool ImmSetConversionStatus(  IntPtr himc,  IntPtr dw1,  IntPtr dw2  );   [DllImport("imm32.dll", EntryPoint = "ImmReleaseContext")]  public static extern int ImmReleaseContext(  IntPtr hwnd,  IntPtr himc  );   }  } 
灵雨飘零 2011-08-02
  • 打赏
  • 举报
回复
老毕 2011-08-02
  • 打赏
  • 举报
回复
三步走:
1. “软键盘”这东西,NET提供有可用的控件吗?如果没有,自己写一个
2. 有了“软键盘”,为其绑定一个textBox
3. 在软键盘的点击事件里,根据点的键,更改textBox的Text

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧