问题描述
大家好...
我在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
推荐答案
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#问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!