[英]VBA Excel: How can I make one form change the position of another form?
I have two forms, frmPE and frmCRE. 我有两种形式,frmPE和frmCRE。 They are modal. 他们是模态的。
frmCRE has a button "Edit PE" that will open formPE (instance of frmPE). frmCRE有一个“编辑PE”按钮,它将打开formPE(frmPE的实例)。 If I don't play with the positions, formPE opens centered on top of frmCRE. 如果我不喜欢这些职位,formPE将以frmCRE顶部为中心打开。 I would like to position them side by side so I can see both at once. 我想将它们并排放置,以便同时看到它们。
When I open frmPE, I can still see frmCRE but not touch it. 当我打开frmPE时,仍然可以看到frmCRE,但不能触摸它。 That's OK. 没关系。
' This code is in cmdEditPE '这段代码在cmdEditPE中
Set formPE = New frmPE
Load formPE
If Not formPE.bInitialize(vbFalse) Then Err.Raise glHANDLED_ERROR
Me.Left = 100 ' move frmCRE to the left so I can see it
formPE.Left = Me.Left + Me.Width ' move frmPE to move to the right side of frmCRE (bad)
formPE.Show
I think the problem is that when formPE opens, it uses its default left setting. 我认为问题在于,当formPE打开时,它将使用其默认的左设置。 From within PE, I can see that me.Left = 0 even though it was set before the show. 从PE内部,我可以看到me.Left = 0,即使它是在演出前设置的。
Is there a way I can use the formPE.bInitialize routine to see that frmCRE is open and find out its LEFT and WIDTH so I can set formPE.Left correctly, or a way I can set it from frmCRE as I was trying to do above? 有没有办法我可以使用formPE.bInitialize例程来查看frmCRE是打开的并找出其LEFT和WIDTH,以便我可以正确设置formPE.Left,或者可以按照上面的尝试从frmCRE进行设置。 ?
Thanks Shari 谢谢Shari
Use the Activae
event of frmPE
to move itself, but only if frmCRE
is visible. 使用Activae
的事件frmPE
自身移动,但只有当frmCRE
是可见的。
In frmPE
在frmPE
Private Sub UserForm_Activate()
If frmCRE.Visible Then
Me.Left = frmCRE.Left + frmCRE.Width
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.