简体   繁体   English

Forms 关闭/显示 - C#

[英]Forms Closing/Showing - C#

I am developing my first UI C# program.我正在开发我的第一个 UI C# 程序。 I am hoping for some help.我希望能得到一些帮助。 My first form contains a few textboxes, and two radio buttons and a Go button.我的第一个表单包含几个文本框、两个单选按钮和一个 Go 按钮。 If one radio button is checked it opens a new small form, if the other is checked it opens a new large form.如果选中一个单选按钮,则会打开一个新的小表单,如果选中另一个,则会打开一个新的大表单。

when the user clicks go - this is my code -当用户点击 go - 这是我的代码 -

        this.WindowState = FormWindowState.Minimized;
        int.TryParse(tbHrs.Text, out hours);
        int.TryParse(tbMins.Text, out minutes);
        int.TryParse(tbSecs.Text, out seconds);
        int.TryParse(tbWarn1.Text, out warn1);
        int.TryParse(tbWarn2.Text, out warn2);


        bool Max = rbMax.Checked;
        if (Max == true)
        {
            if (_Max == null || _Max.IsDisposed)
            {
                _Max = new Max(hours, minutes, seconds, warn1, warn2);
            }
            _Max.Show();


        }
        else
        {
            if (_Min == null || _Min.IsDisposed)
            {
                _Min = new Min(hours, minutes, seconds, warn1, warn2);
            }
            _Min.Show();
        }

so it minimizes the form where the values were entered and passes across the values to start counting down when constructing the new form.所以它最小化输入值的表单,并在构建新表单时传递值以开始倒计时。 On the new form I want to have buttons to pause, which work fine.在新表单上,我想让按钮暂停,效果很好。 However I also want a stop/reset button.但是我也想要一个停止/重置按钮。 So on stop/reset click i want to close the current form but then I want to bring the first form open from minimize state - i tried the commented out line below but it did not work.因此,在停止/重置单击时,我想关闭当前表单,但随后我想从最小化 state 打开第一个表单 - 我尝试了下面注释掉的行,但它没有用。 Does anyone know of way I can show the first user input form from minimize state when stop close on the second form is clicked and even better if it could reset the fields to blank on my first form.有谁知道我可以在第二个表单上单击停止关闭时从最小化 state 中显示第一个用户输入表单的方法,如果它可以在我的第一个表单上将字段重置为空白,那就更好了。 Many Thanks.非常感谢。

    private void MinStop_Reset_Click(object sender, EventArgs e)
    {
        this.Close();
        //ParentForm.Show();
    }

Add an event on the second form (you could subscribe to the existing Form.Closed event but you may want a more specific event for your use case).在第二个表单上添加一个事件(您可以订阅现有的 Form.Closed 事件,但您可能希望为您的用例提供更具体的事件)。

public event EventHandler UserStoppedEvent;

Subscribe to it from your first form and do whatever you need to从您的第一个表单订阅它并做您需要做的任何事情

_min.UserStoppedEvent += (s, e) => {this.WindowState = FormWindowState.Maximized;} 

In the parent form do:在父表单中执行:

_min.FormClosed += (s1,e1) =>  { this.WindowState = FormWindowState.Maximized; }

You need to pass ParentForm handle to the constructor of those small forms.您需要将 ParentForm 句柄传递给那些小的 forms 的构造函数。 Also look here: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.parent.aspx and also here: http://www.daniweb.com/software-development/csharp/threads/120120 Also look here: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.parent.aspx and also here: http://www.daniweb.com/software-development/csharp /线程/120120

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

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