C#GUI-在froms之间导航 [英] c# gui - navigate between froms

查看:112
本文介绍了C#GUI-在froms之间导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编程c#GUI,我有2种形式.
Form1是我的主要表单,它有一个打开form2的按钮.
单击form1中的按钮时,我将隐藏form1,创建一个新的form2对象并显示form2.

我在form2中有一个后退按钮.我希望此按钮的行为关闭form2,然后再次显示隐藏的form1.

我该怎么办?

谢谢

Hi,

I''m programming c# GUI and I have 2 forms.
Form1 is my main form, and it has a button to open form2.
When the button in form1 is being clicked, I hide form1, create a new object of form2 and show form2.

I have a back button in form2. I want the behavior of this button to close form2, and show again the hidden form1.

How can I do it?

Thanks

推荐答案

您能简单地使用表格. ShowDialog方法 [^ ] .窗体2上的后退按钮将关闭form2,因此控件将自动返回到form1.

如果需要,可以使用例如在ShowDialogCall之前隐藏表格1. http://msdn.microsoft.com/zh-CN/library/system.windows.forms.control.hide.aspx [
Could you simply use Form.ShowDialog Method [^]. The back button on form 2 would close the form2 so the control would automatically get back to form1.

If needed, the form 1 could be hidden before the ShowDialogCall using for example: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx[^]


您可以使用Mika的答案,或者您可以这样做:
在form2的后退按钮上写道:

you can go with the Mika''s answer or you can do this:
on back button of form2 write:

private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            Form1 frm = new Form1();
            frm.Show();//or
//frm.ShowDialog();

        }



希望对您有所帮助:)



hope it helps :)


这篇关于C#GUI-在froms之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆