Mdi应用工具条合并 [英] Mdi Application Toolstrip Merging

查看:65
本文介绍了Mdi应用工具条合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个mdi应用程序.

在mdi父窗体中,我有一个工具栏,其中包含新按钮和打开按钮.
在子窗体中,我有带有保存和提交按钮的工具栏.

如果我打开子窗体,则子窗体的工具栏将与mdi父级的工具栏合并,以便该工具栏包含新的,打开的,保存的和提交的按钮.

我的问题是:如果单击了新按钮,如果打开了mdi子窗体,那么该子窗体中的相应函数将被执行(如果存在),否则将执行mdi父窗体中的函数. ="h2_lin">解决方案

确保已为MDI父窗体的MdiChildActivate事件创建了事件处理程序,并使用以下代码:

 私有 无效 Main_MdiChildActivate(对象发​​件人,EventArgs e)
{
ToolStripManager.RevertMerge(toolMain);

MdiChildForm frmChild = ActiveMdiChild  as  MdiChildForm;
如果(frmChild!= )
{
    //  frmChild.FormToolStrip是一个公开的属性
    // 子窗体上的工具栏
    ToolStripManager.Merge(frmChild.FormToolStrip,toolMain);
} 



仅此而已,您就很高兴了!
祝你好运,
爱德华(Eduard)


好吧,再次……我希望你现在能得到它:

ToolStrip添加到您的MDI父窗口.在工具栏上添加一个按钮,并将其命名为(例如)toolButtonNew.将toolButtonNewText属性设置为 New .

现在创建一个新表单(将成为您的MDI子表单,并在子表单中添加ToolStrip.在工具栏上添加一个按钮并为其命名(例如)mdiChildToolNew.设置Text属性的mdiChildToolNew New (必须与MDI父级上工具按钮的Text属性值相同).现在这很重要MergeAction属性设置为Replace.

现在回到您的MDI父窗体,并为MdiChildActivate事件添加一个事件处理程序,并添加以下代码:

 私有 无效 Main_MdiChildActivate(对象发​​件人,EventArgs e)
{
    ToolStripManager.RevertMerge(toolMain);

    MdiChildForm frmChild = ActiveMdiChild  as  MdiChildForm;
    如果(frmChild!= )
    {
        //  frmChild.FormToolStrip是一个公开的属性
        // 子窗体上的工具栏
        ToolStripManager.Merge(frmChild.FormToolStrip,toolMain);
    }
} 



结果是您的MDI父级始终包含一个按钮,该按钮将在MDI父级上触发.现在,如果您打开MDI子窗体(作为MDI父级的MDI子级),则上面的代码将替换MDI父级的ToolStrip上的按钮,然后事件将在MDI子级上触发.如果希望在MDI子级中向MDI父级工具栏添加一个按钮,请将MergeAction属性设置为所需的值(例如Insert).

我希望你现在就明白!

爱德华


I am building an mdi application.

In the mdi parent form I have a toolstrip which conatins new and open button.
In the childforms I have toolstrip which has save and submit buttons.

If I open the childform then the toolstrip of the childform gets merged with the toolstrip of the mdi parent so that the toolstrip contains new, open, save and submit buttons.

My question is: How can I implement, if the new button is clicked, if the mdi child form is opened then the corresponding function in the child form gets executed if it exists otherwise the function in the mdi parent form gets executed.

解决方案

Make sure you''ve created an event handler for the MdiChildActivate event of your MDI Parent form and use the following code :

private void Main_MdiChildActivate(object sender, EventArgs e)
{
ToolStripManager.RevertMerge(toolMain);

MdiChildForm frmChild = ActiveMdiChild as MdiChildForm;
if (frmChild != null)
{
    // The frmChild.FormToolStrip is a property that exposes the
    // toolstrip on your child form
    ToolStripManager.Merge(frmChild.FormToolStrip, toolMain);
}



That''s all, you''re good to go!
Good luck,
Eduard


OK, once again... I hop you''ll get it now :

Add a ToolStrip to your MDI Parent window. Add a button to the toolstrip and name it (for example) toolButtonNew. Set the Text property of toolButtonNew to New.

Now create a new form (which will be your MDI Child form and add a ToolStrip to the child form. Add a button to the toolstrip and name it (for example) mdiChildToolNew. Set the Text property of the mdiChildToolNew to New (this must be the same as the Text property value of the tool button on the MDI Parent). Now this is important set the MergeAction property to Replace.

Now go back to your MDI Parent form, and add an event handler for the MdiChildActivate event and add the follwoing code :

private void Main_MdiChildActivate(object sender, EventArgs e)
{
    ToolStripManager.RevertMerge(toolMain);

    MdiChildForm frmChild = ActiveMdiChild as MdiChildForm;
    if (frmChild != null)
    {
        // The frmChild.FormToolStrip is a property that exposes the
        // toolstrip on your child form
        ToolStripManager.Merge(frmChild.FormToolStrip, toolMain);
    }
}



The result is that your MDI Parent always contains a new button, which will fire on the MDI Parent. Now if you open the MDI Child form (as MDI Child of the MDI Parent), the code above will replace the button on the ToolStrip of your MDI Parent and then the event will fire on the MDI Child. If you wish to add a button from the MDI Child to the MDI Parent toolstrip, set the MergeAction property to the desired value (for example Insert).

I hop you''ll get it now!

Eduard


这篇关于Mdi应用工具条合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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