c# - How do I focus on a form after entering a textbox
问题描述
I'm not sure if focus is the right word but I have an on key up event on my form that will open a new form and close the current form, however after i enter a textbox or other such object i can't re select the form to be able to activate the key up event
This is code a I am using currently when i click on my form, to try select my currently open form however it does not close the current form when i active the key up event, when i do it this way
private void frmLevel1_Click(object sender, EventArgs e)
{
this.BackColor = GlobalClass.BG;
frmLevel1 lvl1 = new frmLevel1();
lvl1.Select();
}
解决方案
我不是 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();
}
}
推荐阅读
- python - 恢复 seq2seq Tensorflow 模型后的错误预测
- ckeditor5 - CKEditor 5 上的包装器
- vue.js - 与电子捆绑在一起时,Axios 似乎无法正常工作,如何对使用电子编译的 exe 进行故障排除?
- python - Django REST 框架隐藏特定的序列化器字段
- xaml - 在 Xamarin.Forms.UWP 中,如果未使用 SetNativeControl() 方法,则无法将自动化 ID 设置为自定义控件
- javascript - 运行播放命令时未定义的歌曲
- ios - 如何在 Swift UI 中删除 Picker 视图的灰色背景框
- c# - 如何在 Visual Studio C# 中使用 WinForms 中的按钮滚动到一侧?
- javascript - 文本选择和替换在 textarea 中无法正常工作
- c# - 使用 sqlite-pcl 和通用存储库存储具有类属性的自动映射对象