中心form1到form2 [英] Center form1 to form2

查看:90
本文介绍了中心form1到form2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有关于vb.net表单定位的问题。我有两种形式,form1和form2。我在form1中有一个按钮来显示表单2.但当我移动form1并单击按钮form2显示不在中心。我希望form2始终显示在form1的中心,即使它来自另一个位置。谢谢

Hello guys,

I have a question regarding vb.net form positioning. i have two forms, form1 and form2. i have a button in form1 to show form 2. but when i move form1 and click the button form2 show not in the center. I want form2 always show in the center of form1 even it from another location. thanks

推荐答案

如果您不介意表格显示模态,那么这将有效:

If you do not mind the form being shown modal, then this would work:
Dim f2 As New Form2
f2.StartPosition = FormStartPosition.CenterParent
f2.ShowDialog()



否则:


Else:

Dim f2 As New Form2
f2.StartPosition = FormStartPosition.Manual
f2.Location = New Point(Me.Location.X + Me.Width \ 2 - f2.Width \ 2, Me.Location.Y + Me.Height \ 2 - f2.Height \ 2)
f2.Show()



其中我是显示f2的表格。


Where "Me" is the form that shows "f2".


你可以很容易地手动完成,但也可以看一下: http://www.blogscrum.com/2011/09/how-to-make-a-mdi-child-window-start-up-in -center-of-parent-window / [ ^ ]
You can do it manually really easily, but look also here: http://www.blogscrum.com/2011/09/how-to-make-a-mdi-child-window-start-up-in-center-of-parent-window/[^]


将Form2的StartupPosition属性设置为CenterOwner



当您使用Show或ShowDialog从Form1打开表单时,将ownerform作为参数添加到方法调用中:



Dim frm2 As New Form2

frm2.ShowDialog(Me)



我在哪里表格你叫它来自,即Form1
Set Form2''s StartupPosition property to CenterOwner

When you open the form from Form1 using Show or ShowDialog, add the ownerform as parameter to the method call:

Dim frm2 As New Form2
frm2.ShowDialog(Me)

Where Me is the form you''re calling it from, i.e. Form1


这篇关于中心form1到form2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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