关闭第二个表单后,在主窗体上关注文本框 [英] Focus textbox on main form after closing a second form
问题描述
如何在关闭通过调用 我试图在关闭和关闭事件中调用 我正在使用 谢谢。 窗体,使一个按钮(或另一个控制)返回一个 ShowDialog()$ c打开的第二个表单后,如何在主表单上关注
TextBox
元素
MainForm.TextBox.Focus()
但是这不会集中文本框。
System.Windows.Forms
在紧凑的框架中。
DialogResult
进入属性。当你想要关闭第二个窗体(即按下按钮后),使其返回一个特定的 DialogResult
。在你的主表单中,你可以这样做:
$ b $ pre $ $ $ $ $ c $ if(secondform.ShowDialog()== DialogResult.OK)
{
textBox.Focus();
调用 ShowDialog )
会阻塞,直到它被关闭,所以你可以简单地做到:
$ b $ pre $第二个form.ShowDialog();
textbox.Focus()
然而,第一个例子是当你只想做在按下某个按钮或在第二个窗体上执行操作后,文本框会有焦点。
How do I focus a TextBox
element on the main form after closing a second form which is opened by calling ShowDialog()
?
I have tried to call MainForm.TextBox.Focus()
in the closing and closed event of the second form, but this won't focus the textbox.
I am using System.Windows.Forms
on the compact framework.
Thanks.
From your second form, make a button (or another control) return a DialogResult
by going into Properties. When you want the second form to close (ie after you press a button) make it return a specific DialogResult
. In your main form you can do this:
if(secondform.ShowDialog() == DialogResult.OK)
{
textBox.Focus();
...
}
Calling ShowDialog()
will block until it is closed so you could simply do:
secondform.ShowDialog();
textbox.Focus()
However the first example is for when you only want to make the textbox have focus after you press a certain button or do an action on the second form.
这篇关于关闭第二个表单后,在主窗体上关注文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!