[英]C#, How to Consistantly bring a form to the front?
I have a MainForm
Class Instance, I bring up another form like so; 我有一个
MainForm
类实例,我提出了另一个这样的形式;
InputForm MyInput= new InputForm("Enter a Number");
MyInput.ShowDialog();
I close MyInput
form from within itself like this; 我从这个内部关闭
MyInput
表单;
private void Button_Click(object sender, EventArgs e)
{
//Do things here
this.Hide();
}
Flow resumes in the MainForm and using either 流程在MainForm中恢复并使用其中任何一个
this.Show();
or 要么
this.Activate();
neither will consistantly bring the MainForm
to the front. 也不会将
MainForm
带到前面。 How can I do this? 我怎样才能做到这一点?
What you need to do is show your InputForm like this. 你需要做的是像这样显示你的InputForm。 This form of ShowDialog assigns the owner to your dialogbox.
这种形式的ShowDialog将所有者分配给您的对话框。
DialogResult dr = MyInput.ShowDialog(this);
//test for result here
MyInput.Close();
this.Hide()
appears to be hiding the main form, not the input. this.Hide()
似乎隐藏了主窗体,而不是输入。 Because ShowDialog
is a blocking method, the InputForm will need to be closed by user action, code internal to the InputForm, or by another thread. 因为
ShowDialog
是一种阻塞方法,所以InputForm需要由用户操作,InputForm内部代码或其他线程关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.