通过Windows c中的MDI父窗体在同一位置打开所有子窗体# [英] Opening all the child form at a same location through MDI parent form in windows c#

查看:87
本文介绍了通过Windows c中的MDI父窗体在同一位置打开所有子窗体#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我通过MDI父级打开新表单时,无论它是相同还是不同的形式,它都会更改其位置。我认为它必须是默认行为,但我想在同一位置打开所有表单,



如果用户通过MDI父级打开多个表单,最近打开的表单将离开屏幕,用户必须在中心手动拖动它们(这对他们来说很烦人。)



下面是打开孩子的代码通过MDI父母形成



Every time I open a new form through a MDI parent regardless it is same or different form, it changes its location. I assume that it must be a default behavior, But I would like to open all the form at SAME LOCATION,

If user opens multiple forms through a MDI parent, recently opened forms will go out of the screen and user have to drag them manually at the center(this would be annoying for them.)

Below is the code for opening child form through MDI parent

frmCreateClient childForm = new frmCreateClient();
            childForm.MdiParent = this;
            childForm.Text = "New Client";
            childForm.Show();





我试图在上面的代码中添加位置如下,但它没有工作





I tried to add location in the above code as below, but it didn't work

childForm.Location = new Point(15, 15);

推荐答案

这是一个想法:谁需要MDI?为什么要折磨自己并吓跑你的用户?

帮自己一个大忙:根本不要使用MDI。没有它,您可以更轻松地实现设计,质量更好。 MDI甚至被微软高度劝阻,事实上,微软将其从WPF中删除并且很难支持它。更重要的是,如果您使用MDI,您将吓跑所有用户。只是不要。请参阅:

http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [ ^ ],

如何在WPF中创建MDI父窗口? [ ^ ]。



我可以解释做什么。请看我过去的答案:

如何在WPF中创建MDI父窗口? [解决方案2 ],

关于在WPF中使用MDI窗口的问题 [ ^ ],

麦当劳给出错误 [ ^ ],

如何设置子窗体最大化,最后一个子窗体最小化 [ ^ ]。



-SA
Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA


您离该位置很近。但是,为了确保使用Location属性将表单放在所需的位置,必须先将StartPosition设置为Manual。



将StartPosition设置为手动将允许Location属性实际工作正常。



You are close with the location. However to ensure the form is placed where you want using the Location property, you must first set the StartPosition to Manual.

Setting the StartPosition to manual will allow the Location property to actually work correctly.

frmCreateClient childForm = new frmCreateClient();
childForm.MdiParent = this;
childForm.Text = "New Client";
childForm.StartPosition = FormStartPosition.Manual;
childForm.Location = new Point(15,15); // Always opens the forms at 15,15
childForm.Show();


您需要将子项的启动位置设置为父级的中心,并且所有表单都将在同一位置打开。请考虑以下代码。



You need to set startup position of your childs to center to parent and all forms would open at same location. consider the following code for same.

frmCreateClient childForm = new frmCreateClient();
          childForm.MdiParent = this;
          childForm.Text = "New Client";
          childForm.StartPosition = FormStartPosition.CenterParent;
          childForm.Show();





希望它对你有帮助.....



Hope it helps you.....


这篇关于通过Windows c中的MDI父窗体在同一位置打开所有子窗体#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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