如何在C#中加载父窗口? [英] How to load the parent window in C# ?

查看:61
本文介绍了如何在C#中加载父窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个窗口,其中包含很少选项的菜单栏。当我点击第一个菜单项时,我可以隐藏具有菜单的窗口并加载子窗口。但是我想在关闭子窗口后立即加载主菜单窗口。我创建了一个主菜单窗口类型的对象并执行了win.show();那不会发生。什么是解决方案? Plz帮助我



我尝试过:



这段代码是单击保留菜单项时加载保留窗口

I have created window having menu bar with few options. When I click on the first menu item I am able to hide the window having menu and load the child window. But I want to load the main menu window as soon as I close the child window. I created an object of type main menu window and executed win.show(); thats not happening. Whats the solution? Plz help me

What I have tried:

this code is to load the reserve window when Reserve menu item is clicked

private void Reserve_Click_1(object sender, RoutedEventArgs e)
{
            ReservationForm reswin = new ReservationForm();
            //MenuWin win1 = new MenuWin();
            this.Close();
            reswin.Show();
}





这是预订表格关闭时加载菜单窗口的代码





this is the code for loading menu window when the reserve form is closed

private void ResForm_Closed(object sender, EventArgs e)
{
            MenuWin win1 = new MenuWin();
            win1.Focus();
            win1.Show();
}

推荐答案

最简单的方法是这样做:

The simplest way is to do this:
Hide();
MenuWin win1 = new MenuWin();
win1.ShowDialog();
Show();

因为你隐藏了原文,然后使用ShowDialog而不是Show,直到新窗口关闭后,控件才会返回到窗体。然后,您只需再次显示原始表单,即可访问用户使用的新表单的属性。

Because you hide the original, and then use ShowDialog instead of Show, control will not come back to the form until after the new window is closed. Then you just show the original form again, and you can access the properties of the new form that the user played with.


这篇关于如何在C#中加载父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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