在按钮单击事件中,将一个标签放入具有多个文本框中的光标的文本框中 [英] Put a lable in text box which haveing curser from multiple text boxes at button click event
本文介绍了在按钮单击事件中,将一个标签放入具有多个文本框中的光标的文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
中午好,
我的表单具有名称"按钮,3个文本框,在单击事件时,我必须在文本框内放置一个标签,该标签的光标位于光标所在的位置.
Good After Noon,
My form having Button "Name", 3 text boxes, At the time of click event, i have to place a label in text box which is having cursor at the position of cursor.
推荐答案
您必须记住"单击按钮时的位置,因此在类级别上,创建一个变量:
You have to "remember" where you were when you clicked the button, so at class level, create a varaiable:
private TextBox lastUsed = null;
使用相同的处理程序处理所有三个文本框的Leave事件,然后执行以下操作:
Handle the Leave event for all of the three textboxes with the same handler, and do this:
private void allMyTextBoxes_Leave(object sender, EventArgs e)
{
lastUsed = sender as TextBox;
}
然后,在按钮单击事件中,您可以执行以下操作:
Then, in your button click event, you can do this:
private void butPutTextInLastTextBox_Click(object sender, EventArgs e)
{
if (lastUsed != null)
{
lastUsed.Text = "Hello";
}
}
buttonName.Click += (sender, eventArgs) => {
myTextBox.Text =
myTextBox.Text.Insert(
myTextBox.Text.SelectionStart,
myLabel.Text);
};
这篇关于在按钮单击事件中,将一个标签放入具有多个文本框中的光标的文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文