4
我使用Windows窗体,我有2个按钮和一个文本框。如何在输入文字框时专注于TextBox?
button1.text = 1 and button2.text = 2;
我点击其中一个按钮,以便将其文本输入到texbox中,但文本框失去焦点并且闪烁的光标消失,所以我通过在按钮单击中添加“textBox1.Focus()”来解决此问题,现在我有闪烁的光标,但新问题出现了:每当我键入一个字母(通过单击一个按钮),整个文本就会突出显示。
如何在点击按钮时保持闪烁的光标(设置焦点文本框)并摆脱突出显示的文本? 谢谢
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ActiveControl = textBox1;
textBox1.Focus();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button1.Text;
textBox1.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + button2.Text;
textBox1.Focus();
}
}
伊戈尔。它像魔术一样工作。谢谢 – naouf