简体   繁体   English

如何阻止弹出窗体

[英]How to stop form from popping up

I have a program where I am taking data from one form to the next, so it displays the same data on each form. 我有一个程序,我将数据从一个表单转移到下一个表单,因此它在每个表单上显示相同的数据。 Though when I try to Close the form or Hide it, one of the other forms that relayed the information from form 2 to form 3 keep showing up when I try to close form 3 and move to form 4. How do I close form 2 so that it doesn't come up anymore? 虽然当我尝试关闭表单或隐藏它时,在我尝试关闭表单3并转到表单4时,将表单2中的信息转发到表单3的其他表单之一会继续显示。如何关闭表单2以便它不再出现了吗?

Here is my current code from form 2 that relays over to form 3: I set this at the below the initializing component to read in the data from form 1 这是我目前从表单2转发到表单3的代码:我在下面的初始化组件中设置它来读取表单1中的数据

public string Username { get; set; }
public string MSG { get; set; }

Then I read in the values in the form2 load 然后我读取form2加载中的值

label4.Text = Username;
label5.Text = MSG;

Then I try to relay the information to form 3 in a timer that is enabled for only 3 seconds: 然后我尝试在一个只启用3秒的计时器中将信息转发到表单3:

using (var f = new form3())
{
     try
     {
         f.Username = label4.Text;
         f.MSG = label5.Text;
         f.ShowDialog();
     }
     catch
     {
         Application.Exit();
     }
     this.Close();
}

And then on form3 I try to use a button to go to form 4 and form 2 shows up again... 然后在form3上我尝试使用一个按钮转到表单4并再次显示表单2 ...

private void button1_Click(object sender, EventArgs e)
{
     form4.Show();
     this.Close();   
}

How do I stop this? 我怎么阻止这个?

Thanks. 谢谢。

Change this: 改变这个:

form4.Show();

To this: 对此:

form4.ShowDialog();

You're showing Form4 nonmodal, so this.Close() is immediately executed and Form3 closes. 您正在显示Form4非模态,因此立即执行this.Close()并关闭Form3。 Form4 is still open but probably just drops to the background and Form2 comes back up to the front. Form4仍处于打开状态,但可能只是落到后台,而Form2又回到了前面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM