文本框的C#问题 [英] C# problem with textbox

查看:72
本文介绍了文本框的C#问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...
我在winform应用程序中有大约5个文本框,我有一个按钮,还有一个文本框仅用于写信.光标在哪里

Hello everybody ...
i have about 5 textbox in my winform aplication, i hava a button, and a textbox apart just for writtin.. the thing is that i want that went i click the button, text that is in the textbox for write, go to a textbox where is the cursor

推荐答案

这并不困难.
您所需要做的就是设置一个私有类级别的TextBox变量,以保存您所处的最后一个,并为要接收信息的5个文本框构造一个Leave事件处理程序-它们都转到同一个:
It''s not difficult.
All you have to do is set up a Private class level TextBox variable to hold the last one you were in, and construct an Leave event handler for the 5 textboxes you want to recieve the information - they all go to the same one:
private TextBox lastCursor = null;
private void tbWithCursor_Leave(object sender, EventArgs e)
    {
    lastCursor = sender as TextBox;
    }

按钮单击事件非常简单:

The button click event is then simple:

private void butMoveText_Click(object sender, EventArgs e)
    {
    if (lastCursor != null)
        {
        lastCursor.Text = tbForWriting.Text;
        }
    }

发生的事情是,当焦点离开文本框时(即,它具有光标,但是其他控件正在变为活动控件),将保存文本框的标识.单击按钮时,最后保存的值是您想将文本放入其中的TextBox.

简单!

What happens is that when the focus leave a TextBox (i.e. it had the cursor in it, but some other control is becoming the active control) the identity of the TextBox is saved.When you click the button, the last saved value is teh TextBox you want to put your text into.

Simples!


这篇关于文本框的C#问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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