我不确定焦点是否正确,但是我的表单上有一个on key up事件,它将打开一个新表单并关闭当前表单,但是在输入文本框或其他类似对象之后,我可以重新选择表单以激活按键事件
这是我在单击表单时尝试使用的当前代码,以尝试选择当前打开的表单,但是当我以这种方式进行激活键激活事件时,它不会关闭当前表单
private void frmLevel1_Click(object sender, EventArgs e)
{
this.BackColor = GlobalClass.BG;
frmLevel1 lvl1 = new frmLevel1();
lvl1.Select();
}
答案 0 :(得分:0)
我不确定100%,但是您有几个不同的问题。希望对您有所帮助。
// Button click event
private void button1_Click(object sender, EventArgs e)
{
// Focus on textbox
this.ActiveControl = textBox1;
}
// Form load event
private void Form1_Load(object sender, EventArgs e)
{
// Focus on textbox
this.ActiveControl = textBox1;
}
// Close the current form and open another one. Use any event what you want
private void button1_Click(object sender, EventArgs e)
{
using (Form2 frm = new Form2())
{
// Hide the current form. If you close it it will dispose of all further events
this.Hide();
// Open the new form
frm.Show();
// Close the current form
this.Close();
}
}