Treeview菜单隐藏了MDI子窗体,如何解决? [英] Treeview menu hides MDI child frorm How to solve ?

查看:68
本文介绍了Treeview菜单隐藏了MDI子窗体,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用Treeview作为菜单.树视图在中间.当mdi child打开时,它会隐藏在树视图之后.

Hi,
I am using treeview as menu. the treeview is on the mdiparent. when mdi child is open it goes behid the treeview. How the childform will appear at the top of treeview?

推荐答案

我担心对此的解决方法有点丑陋",但MDI体系结构有点像老了,到现在为止."除非您绝对必须使用它,否则我鼓励您考虑MDI以外的另一种体系结构.

也许您可能考虑了将一个表单设置为其他表单的所有者"的能力:这将确保这些拥有的"表单在显示时将以z顺序出现在同一级别;因此它们不会被所有者"表格所覆盖.是的,如果您这样放弃使用MDI所获得的自定义菜单,那么创建自己的菜单就不难了.

MDIParent上的控件(例如TreeView用作菜单)将始终显示在显示的任何MDIChild窗体上方.并且,对MDIParent的这种控制也将影响MDI子表单的放置:

在您的情况下,将任何MDIChild窗体的Left属性设置为#0都会有效地将其左边缘设置为TreeView的右边界(假设,如此处所示,TreeView停靠在MDIParent窗体上的"Left").但是,当您最大化MDI子窗体(假设您不想隐藏其最大化"按钮)时,仍然会发生粘滞"情况.

这是解决(是的,丑陋的")MDI子窗体可以落后于" MDIParent曲面上的控件的问题的想法:

首先是最终用户移动表单的简单情况:
I''m afraid the fix for this is kind of "ugly," but MDI architecture is kind of "old and in the way now." I''d encourage you, unless you absolutely have to use it, to think of another architecture than MDI.

Perhaps you might consider the ability to set one Form as the ''owner'' of other Forms: this will guarantee that these ''owned'' Forms will appear at the same level in the z-order when displayed; so they will not be covered over by the ''owner'' form. Yep, you give up that custom menu you get with MDI if you go this way, but it''s not hard to create on your own.

A control (like your TreeView functioning as menu) on the MDIParent will always appear above any MDIChild Form shown. And, such a control on the MDIParent will also affect the placement of MDI Child Forms:

In your case setting the Left property of any MDIChild Form to #0 will effectively set its left edge to the right border of the TreeView (assuming, as shown here, the TreeView is docked ''Left on the MDIParent Form). But, that still leaves the ''sticky'' case of what happens when you maximize an MDI Child Form (assuming you don''t want to hide its ''maximize'' button).

Here''s an idea for a (yes, "ugly") way to work around the issue that the MDI Child Form can "get behind" a control on the MDIParent surface:

First the simple case of the Form being moved by the end-user:
private Form2 f2;

private void Form1_Load(object sender, EventArgs e)
{
    treeView1.Dock = DockStyle.Left;

    f2 = new Form2();

    f2.Move += new EventHandler(f2_Move);
    f2.SizeChanged += new EventHandler(f2_SizeChanged);

    f2.MdiParent = this;
    f2.Show();
}

private void f2_Move(object sender, EventArgs e)
{
    if (f2.Left < 0) f2.Left = 0;
}

然后,由于用户选择最大化" MDI子窗体以及单击并拖动,可能导致调整大小":

And, then, the case of a ''resize'' which could result from the user choosing to ''Maximize'' the MDI Child Form, as well as click-and-drag:

private void f2_SizeChanged(object sender, EventArgs e)
{
    if (f2.WindowState == FormWindowState.Maximized)
    {
        // must handle Maximized like this unfortunately
        f2.WindowState = FormWindowState.Normal;
        f2.Bounds = f2.MdiParent.ClientRectangle;
        // ugly magic numbers to compensate for form non-client
        // areas ... right and left border areas may vary with
        // OS and features: for example Win7 with Aero 'on' will
        // will have larger right and left borders ...
        f2.Height -= 6;
        f2.Width -= treeView1.Width + 6;
    }

    if (f2.Left < 0) f2.Left = 0;
}

祝您好运,Bill


与Bill Woodruff达成协议:尽一切努力摆脱MDI.如果微软不鼓励的话.停止折磨自己并吓scar客户.

一些支持它的参考资料:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [在WPF中使用MDI窗口的问题 [ ^ ],
提供错误的MDIContainer [
Agree with Bill Woodruff: use whatever it takes to get rid of MDI. If is discouraged even by Microsoft. Stop torturing yourself and scaring off your customers.

Some references in support it:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

—SA


这篇关于Treeview菜单隐藏了MDI子窗体,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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