如何从另一种形式打开一个新形式 [英] How to open a new form from another form

查看:258
本文介绍了如何从另一种形式打开一个新形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这是使用ShowDialog方法打开的表单。在这种形式下,我有一个按钮叫更多。 如果我们点击更应该打开另一种形式,它应该关闭当前的形式。

I have form which is opened using ShowDialog Method. In this form i have a Button called More. If we click on More it should open another form and it should close the current form.

在更多按钮的Click事件处理程序我写了下面的code

on More Button's Click event Handler i have written the following code

MoreActions objUI = new MoreActions (); 
objUI.ShowDialog();
this.Close();

但正在发生的事情是,它不是关闭的第一种形式。所以,我修改了这个code到

But what is happening is, it's not closing the first form. So, i modified this code to

MoreActions objUI = new MoreActions (); 
objUI.Show();
this.Close();

下面,是越来越显示第二种形式,在几秒钟内两个形式得到休息。

Here, The second form is getting displayed and within seconds both the forms getting closed.

任何人都可以请帮我解决问题。我需要做的是,如果我们点击更多按钮,就应该打开另一个表单并关闭第一种形式。

Can anybody please help me to fix issue. What i need to do is, If we click on More Button, it should open another form and close the first form.

任何形式的帮助将是真的对我很有帮助。

Any kind of help will be really helpful to me.

推荐答案

在我看来,主要的形式应该是负责打开两个子窗体。下面是一些伪,说明我会做什么:

In my opinion the main form should be responsible for opening both child form. Here is some pseudo that explains what I would do:

// MainForm
private ChildForm childForm;
private MoreForm moreForm;

ButtonThatOpenTheFirstChildForm_Click()
{
    childForm = CreateTheChildForm();
    childForm.MoreClick += More_Click;
    childForm.Show();
}

More_Click()
{
    childForm.Close();
    moreForm = new MoreForm();
    moreForm.Show();
}

您只需要在第一个孩子创建一个简单的事件MoreClick。这种方法的主要好处是在需要时您可以复制它,你可以很容易模拟某种基本的工作流程。

You will just need to create a simple event MoreClick in the first child. The main benefit of this approach is that you can replicate it as needed and you can very easily model some sort of basic workflow.

这篇关于如何从另一种形式打开一个新形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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