c# - 如何在不在 C# Windows 应用程序中创建父类的新实例的情况下返回父窗体

标签 c# .net winforms

如何在 C# Windows 应用程序中不创建父窗体的新实例就返回到父窗体? 我已经尝试过 this.Parent、this.MdiParent、this.MyParentForms,但没有人成功。

最佳答案

您的父表单中可以有一个按钮,用于显示另一个表单。将此代码添加到按钮的 Click 事件中:

//Click event of your button.
private void goToSecondForm_Click(object sender, EventArgs e)
{
   this.Hide(); //Hides the parent form.
   subform.ShowDialog(); //Shows the sub form.
   this.Show(); //Shows the parent form again, after closing the sub form.
}

关于c# - 如何在不在 C# Windows 应用程序中创建父类的新实例的情况下返回父窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222547/

相关文章:

c# - 如何根据 #var=test 变量更改图像的图像 url?

c# - 为什么 MassTransit 不将消息推送到 MSMQ,除非有订阅者?这是如何解决的?

wpf - 如何将 WPF 对话框添加到 Winforms 项目

WinForms 的 iPhone UI 控件

mysql - vb.net 中登录表单的散列密码

c# - 将 Azure MS Graph API 服务帐户与托管标识结合使用

c# - 异常转换

c# - 命令在我自定义的 UserControl 中内置的事件上不起作用/触发

c# - 如何针对不同尺寸的设备调整gridview的尺寸

C# 在 WebBrowser 中调用 JavaScript