如何在无模式表单上定位模态表单 [英] how to position a modal form on top of a modeless form

查看:88
本文介绍了如何在无模式表单上定位模态表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我是C#编程的新手,我在定位模态表单时遇到了麻烦。我基本上有一个主窗体(frmFormA)设置为mdi父级,然后在frmFormA上按下一个按钮,我在特定位置打开另一个窗体(frmFormB)。 frmFormB打开如下:

FormB = new frmFormB();

FormB.MdiParent = this;

FormB.Show();


现在从frmFormB,按下按钮,我想打开另一个表单,但我希望它要求用户在它可以关闭之前做某事。所以我这样打开它:

FormC = new frmFormB();

FormC.ShowDialog();


我这样做,FormC并不完全在FormB之上。即使我将它设置为与FormB相同的位置,它略高并且向左。如果我改变我的代码以打开FormC,就像我打开FormB一样,它将FormC放在我想要的地方。


我希望我能清楚地解释我的问题。如果没有,请告诉我。我正在使用带有3.5框架的Visual Studio 2008。谁能告诉我如何通过这个?谢谢。

hello. i am new to programming in C# and i''m having trouble positioning a modal form. i basically have a main form (frmFormA) set as a mdi parent, then a button is pressed on frmFormA and i open another form (frmFormB) at a particular location. frmFormB is opened up as follows:
FormB = new frmFormB();
FormB.MdiParent = this;
FormB.Show();

Now from frmFormB, a button is pressed and i want to open another form, but i want it to require the user to do something before it can close. So I am opening it like this:
FormC = new frmFormB();
FormC.ShowDialog();

When i do this, FormC doesn''t go exactly on top of FormB. It is slightly higher and to the left even though i''m setting it to the same position as FormB. If i change my code to open FormC the same way as I open FormB, it places FormC where i want it.

I hope i have explained my problem clearly. If not, please let me know. I am using Visual Studio 2008 with the 3.5 framework. Can anyone tell me how to get past this? Thanks.

推荐答案

FormB知道自己的位置和大小。

您可以在创建时将此信息传递给FormC。

FormC内部使用传递的信息手动设置它的位置。


FormC = new frmFormB(this.Location.X,this.Location.Y,this .Width,this.Height)
FormB knows its own location and size.
You could pass this information to FormC when you create it.
Inside FormC use the passed information to manually set it''s location.

FormC = new frmFormB(this.Location.X, this.Location.Y, this.Width, this.Height)


感谢您的回复。我尝试了这个,当我使用Show()时它工作正常,但是当我将它改为ShowDialog()时,位置稍微偏离。我假设差异是b / c,当我使用ShowDialog()时,我不能声明父母。所以我猜想当一个表格与父母相关联时,屏幕上的坐标是不同的?有没有人有这方面的解决方法?我可以使用Show(),但我希望我的应用程序停止,直到它收到FormB的响应。感谢您的帮助。
thanks for your reply. I have tried this and it works fine when I use Show(), but when i change it to ShowDialog(), the position is slightly off. I''m assuming the difference is b/c when i use ShowDialog(), I can''t declare a parent. So I guess the coordinates on the screen are different when a form is associated to a parent versus when it is not? Does anyone have any workarounds for this? I can use Show(), but i wanted my application to stop until it receives a response from FormB. Thanks for any help.



有没有人为此做过任何变通办法?
Does anyone have any workarounds for this?



您是否尝试过我的建议让表单根据传递给它的位置设置它自己的位置?如果这没有按预期工作,请发布您正在使用的代码来设置位置。

Did you try my suggestion of having the form set it''s own location based on the location passed to it? If that didn''t work as expected, please post the code you are using to set the location.


这篇关于如何在无模式表单上定位模态表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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