【发布时间】:2016-02-15 11:30:46
【问题描述】:
我正在使用 Windows 窗体,我有 2 个按钮和一个文本框。
button1.text = 1 和 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();
}
}
【问题讨论】:
标签: c#