中心家长表格 [英] Center parent form
问题描述
我正在尝试获取一个将父项居中的表单.我已经做了很多谷歌搜索",如果它有效,则没有.
I am trying to get a form to center the parent. I have done lots of 'googling' and none if it has worked.
问题是.当我将表单设置为中心父表单"时,它将起作用,除非父表单从原始起始位置移动.
The issue is. When I have a form set to "Center Parent Form" it will work, unless the parent form is moved from the original starting location.
示例:父表单从屏幕左上角开始.我把它移到中央屏幕.然后我执行和操作有一个弹出窗口,该窗口居中到左上角父窗体的原始位置.不是现在的.视觉:http://imgur.com/a/jGBfP
Example: Parent form starts top left of screen. I move it to center screen. I then preform and action to have a popup window, that window gets Centered to the original location of the parent form in the top left. Not the current one. Visual: http://imgur.com/a/jGBfP
我已将表单属性设置为中心父级"以及
I have set the form properties to be 'Center Parent' as well as
Me.StartPosition = FormStartPosition.CenterParent
推荐答案
您在哪个类和方法中设置 Me.StartPosition
属性?
In which class and method are you setting the Me.StartPosition
property?
你看过这个 Stackoverflow 答案吗?https://stackoverflow.com/a/30199106/1337635
Have you seen this Stackoverflow answer? https://stackoverflow.com/a/30199106/1337635
更新你需要做两件事才能让它工作:-
UPDATE You need to do two things to get this to work:-
根据@mark-hall,您需要显示表单并传入父级:-
As per @mark-hall, you need to show the form and pass in the parent:-
Dim child As frmChild
child = New frmChild()
child.Show(Me) '显式声明父级
根据上面我引用的答案,在子窗体的Load
事件中,需要调用Me.CenterToParent()
As per the above answer I referenced, in the Load
event of the child form, you need to call Me.CenterToParent()
这篇关于中心家长表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!