通过键盘在不同的文本框中键入 [英] Typing through keyboard in different textboxes

查看:59
本文介绍了通过键盘在不同的文本框中键入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有几个文本框,我想在我的Windows应用程序中使用键盘,用户可以通过该键盘输入不同的文本框。

i使用许多按钮和此代码后面的每个按钮制作键盘。

按钮b =发件人 as 按钮; 
Search_Form.tb.Text + = b.Text;



但这只适用于一个文本框。

a genral keyboard i要求用户可以键入任何文本框

解决方案

以下步骤可以解决您的问题



1.在表单中声明一个文本框,如下所示

 private System.Windows.Forms.TextBox txtCurrentBox; 





2.为下面的每个文本框添加Enter事件处理程序

 private void textBox1_Enter(object sender,EventArgs e) 
{
txtCurrentBox =发送者为TextBox;
}





3.添加如下所示的新功能。

 private void TypeToTextBox(object sender)
{
Button b = sender as Button;
if(txtCurrentBox!= null)
{
txtCurrentBox.Text + = b.Text;
}
}





4.点击每个键盘按钮调用此函数给定下面

 private void btn_b_Click(object sender,EventArgs e)
{
TypeToTextBox(sender);
}


使用虚拟键盘和多个键盘输入时,存在一些困难。其中之一是,在一般情况下,输入需要键盘焦点,但点击它会抓住焦点并停用虚拟键盘。这是我的解决方案:您可以使键盘窗口无法调焦,但使用始终在线窗口样式:

应用程序焦点的获得和失败 [ ^ ]。



如果这样做,你可以普遍使用这种键盘,而且不仅仅是在Forms应用程序上(请注意,比如,WPF,在应用程序中,控件不是窗口控件,所以你不能向他们发送Windows消息(不管怎么说都不是最好的想法),但你可以用你的虚拟键盘键入任何东西用 System.Windows.Forms 编写。并且不仅要键入同一个应用程序的控件。



另请参阅我过去对该主题的回答:

创建虚拟键盘 [ ^ ],

在BACKSPACE按钮上编程 [ ^ ]。



-SA

i have several text boxes on a form and i want a keyboard in my windows application by which a user could type in different textboxes.
i made key board using many button and every button behind this code.

Button b = sender as Button;
       Search_Form.tb.Text += b.Text;


but this is working for only one textbox.
a genral keyboard i require by which a user could type in any textbox

解决方案

Following steps may resolve your problem

1. Declare a textbox in your form as given below

private System.Windows.Forms.TextBox txtCurrentBox;



2. Add Enter event handler for every text box like below

private void textBox1_Enter(object sender, EventArgs e)
   {
       txtCurrentBox = sender as TextBox;
   }



3. Add new function like given below.

private void TypeToTextBox(object sender)
   {
       Button b = sender as Button;
       if (txtCurrentBox != null)
       {
           txtCurrentBox.Text += b.Text;
       }
   }



4. On click of every keyboard button call this function as given below

private void btn_b_Click(object sender, EventArgs e)
      {
          TypeToTextBox(sender);
      }


With virtual keyboard and several keyboard inputs, there are some difficulties. One of them is that, in general case, an input need keyboard focus, but clicking on it grabs the focus and deactivates the virtual keyboard. Here is my resolution: you can make the keyboard window not focusable but with "always on top" window style:
Application focus getting and losing[^].

If you do this, you can use such keyboard universally, and not only on Forms application (note that, say, WPF, in applications, controls are not windowed controls, so you cannot send Windows message to them (not the best idea anyway), but you can type in anything with your virtual keyboard written in System.Windows.Forms). And to type not only into the controls of the same application.

See also my past answers on the topic:
Creating a Virtual Keyboard[^],
Programming on BACKSPACE button[^].

—SA


这篇关于通过键盘在不同的文本框中键入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆