简体   繁体   English

VBA Excel:如何使一种表单更改另一种表单的位置?

[英]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.

相关问题 如何将列表视图从一种形式传递到另一种形式? - How can I pass a listview from one form to another form? 如何在Rails的另一个表单中包含一个表单? - How Can I Include One Form within Another Form in Rails? 如何使用VBA在Microsoft 2010中创建必填表格字段? - How can I make a MANDATORY form field in Microsoft 2010 with VBA? 如何使文本以表单形式显示在另一页上? - How can I make text appear on another page in a form? 如何将2个变量从一种形式传递给另一种形式? - How can I pass 2 variables from one form to another? 如何以一种形式进行 2 次搜索(vuetify)? - How can I make 2 search in the one form (vuetify)? 如何在Access VBA中从另一个表单调用一个表单的Form_Load - How to call Form_Load of one form from another form in Access VBA 将一种形式的数据从另一种形式更改 - Change data of one form from another form 如何通过另一种形式的选项按钮VBA的答案更改一种形式的标签的标题 - How do i change the caption of a label from one form due to answer from a option button in a different form, VBA 我如何保存另一个对象,但它具有自己的形式却是第一个对象的形式? - How can I save another object with its own form but in the form of the first one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM