简体   繁体   中英

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%.

FrameA contains a child FrameB, whose .Width is 8000 and whose .Left is 1000 (in FrameA zoomed coordinates). FrameB is fully visible on screen.

I want to move FrameB to the right so that its right edge lies along the right edge of the monitor. 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.

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. 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:

Private Sub cmdExit_Click()
  Unload Me
End Sub

Sub runDemo() has become:

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:

  • UserForm1 occupied the entire screen apart from the Windows Task bar along the bottom.
  • Frame1 was at the top, occupied the full width of the screen and had a height of 300.
  • Frame2 was right aligned with Frame1.
  • The maximized/normal/minimized state of Excel was not changed.

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. Where should the left side of the Frame2 be moved to?

Sub move_Frame2_Hard_Right_Inside_Frame1()
   Dim zoomPct!
   zoomPct! = Frame1.Zoom / 100
   Frame2.Left = Frame1.Width / zoomPct! - Frame2.Width
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM