父母和孩子Windows帮助 [英] Parent and Child Windows Help

查看:64
本文介绍了父母和孩子Windows帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我的c#应用程序中有一个MDI父表单(主表单).
我的应用程序中还有一个子窗口(子窗体1).

当我单击父表单中的选项菜单时,将出现子窗口.
当我再次在此选项菜单中单击时,辅助窗口将被复制,现在
我有两个出现的子窗口.

但是我不希望那样,无论我单击多少次,我都只希望显示一个子窗口.


请给我任何解决方案吗?

在此先感谢...

Hello Friends,

I have a MDI Parent Form (Main Form) in my c# aplication.
Also I have a child windows (Child Form 1) in my aplication.

When I do click in a option menu in my Parent Form, then the child window is appear.
when I do click again in this option menu, the secondary window is duplicated and now
I have two child windows that is appear.

But I do not want that, I want that only one child window will showing, no matter how many click i do.


Please would you give me any solutions???

Thanks in advance...

推荐答案

我想您正在初始化主窗体的菜单单击事件中的子窗口.

在函数外部声明一个子窗体对象,并检查null.

例如:

I guess you are initializing the Child Window inside the Main Form''s menu click event.

Declare a Child Form object outside the function and check for null.

Ex:

ChildForm childForm = null;

private void OnMenuClick (object sender, EventArgs e)
{
    if (childForm == null)
    {
        childForm = new ChildForm();
    }
    childForm.Show(); 
}



关闭ChildForm时必须调用Dispose.

如果有帮助,请将其标记为答案



You must call Dispose when you close the ChildForm.

Mark it as answer if it is helpful


最佳解决方案是:从不使用MDI!绝对不建议使用这种UI样式.
请参见 http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [
对于选项卡式界面示例,请使用以下命令:
标签式MDI子窗体 [ http://www.codeproject.com/info/search.aspx?artkw=tabbed [ ^ ]带有标签:C#,WinForms.

—SA
Best solution is: never use MDI! This UI style is absolutely discouraged.
See http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^].

It is cumbersome in implementation and extremely inconvenient for the users. You could scare them off!
Use tab interface instead; there are other options. Actually, all "advantages" if MDI are also covered by a simple tabbing UI.

For tabbed interface samples, use this: Tabbed MDI Child Forms[^].

For more samples, search http://www.codeproject.com/info/search.aspx?artkw=tabbed[^] with tags: C#, WinForms.

—SA


您所描述的听起来像是非模态对话框.为此,我需要在启动/创建时声明并创建对话框作为主窗体的成员.选择菜单项后,将使用显示和隐藏"功能激活对话框.对话框Closing事件被侦听,只是隐藏表单并在事件处理程序中取消关闭

Your describing a non modal dialog it sounds like. What I do for this is declare and create the dialog as a member of the main form at startup/creation. When the menu item is selected the dialog is activated using Show and Hide functionality. The dialogs Closing event is listened to and just Hide the form and cancel the closing in the event handler

public void OnDialogFormClosing(object sender, CancelEventArgs e)
        {
            m_DialogForm.Hide();
            e.Cancel = true;
        }



此示例具有主要形式的处理,但是您也应该能够在对话框中进行处理.



This example has the handling in the main form but you should be able to handle it in the dialog as well.


这篇关于父母和孩子Windows帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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