[英]Moving controls inside a zoomed frame on an Excel Userform
I have Userform1 which is sized to fit full screen in a monitor of 2560 x 1440. Userform1 contains FrameA whose .Width is also 2560, and which is zoomed to 10%. 我有Userform1,其大小适合在2560 x 1440的监视器中全屏显示。Userform1包含FrameA,其.Width也是2560,并缩放到10%。
FrameA contains a child FrameB, whose .Width is 8000 and whose .Left is 1000 (in FrameA zoomed coordinates). FrameA包含一个子FrameB,其子.Width为8000,其.Left为1000(在FrameA缩放坐标中)。 FrameB is fully visible on screen. FrameB在屏幕上完全可见。
I want to move FrameB to the right so that its right edge lies along the right edge of the monitor. 我想将FrameB向右移动,使其右边缘位于监视器的右边缘。 Could somebody show me the arithmetic for doing that? 有人可以告诉我这样做的算法吗?
I do not recall every having so much trouble getting a form to look the way I wanted. 我不记得每个人都很难在表单上找到自己想要的样子。
I ended up moving lots of things around that did not, perhaps, need moving. 我最终搬了很多东西,也许不需要搬。 However, I have finally got the effect I believe you seek so I have not tried to move code back to where it was. 但是,我终于获得了我相信您所寻求的效果,因此我没有尝试将代码移回原来的位置。
The first key change appears to be: 第一个关键更改似乎是:
Property StartUpPosition of UserForm1 = 0 - Manual`
without this, I could not set the form's height to the full available height. 没有这个,我将无法将表单的高度设置为最大可用高度。 Setting .Top had no effect. 设置.Top无效。
The second key change appears to be use of: 第二个关键更改似乎是使用:
Application.DisplayFullScreen = True
I do not recall needing this command before but maximizing the window state would not give the full screen height. 我不记得之前需要此命令,但最大化窗口状态将无法提供完整的屏幕高度。
I discarded your routines Sub maximizeWindows()
and Sub UserForm_initialize()
either because I did things differently or because I moved the code. 我放弃了Sub maximizeWindows()
例程Sub maximizeWindows()
和Sub UserForm_initialize()
是因为我做的事情有所不同,或者是因为我移动了代码。 I am sure you could move the code back but I have not tried. 我确定您可以将代码移回,但是我没有尝试过。
I added a new control cmdExit
with the following event routine: 我添加了带有以下事件例程的新控件cmdExit
:
Private Sub cmdExit_Click()
Unload Me
End Sub
Sub runDemo()
has become: Sub runDemo()
已变为:
Sub runDemo()
Application.DisplayFullScreen = True
Load UserForm1
With UserForm1
.Top = 2
.Left = 0
.Width = Application.UsableWidth
.Height = Application.UsableHeight - 2
.Frame1.Move 0, 0, .InsideWidth, 300
.Frame2.Left = .Frame1.Left + .Frame1.InsideWidth - .Frame2.InsideWidth
.Show
End With
Application.DisplayFullScreen = False
End Sub
The effect of the above for me was: 以上对我的影响是:
Hope this works for you. 希望这对您有用。
I finally found how to do it. 我终于找到了解决方法。
Just to recap the problem and simplify it a bit: Frame2 is fully contained inside a zoomed Frame1, and needs to be moved to the right so its right side is flush with the right side of Frame1. 为了简单地说明问题并简化一下:Frame2完全包含在缩放的Frame1中,并且需要向右移动,以便其右侧与Frame1的右侧齐平。 Where should the left side of the Frame2 be moved to? Frame2的左侧应移到哪里?
Sub move_Frame2_Hard_Right_Inside_Frame1()
Dim zoomPct!
zoomPct! = Frame1.Zoom / 100
Frame2.Left = Frame1.Width / zoomPct! - Frame2.Width
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.