Controlling size of forms in Access

独自空忆成欢 提交于 2019-12-24 11:44:06

问题


So I have an Access application, and I'd like some forms to be maximised when they are opened, and others to be medium-sized when they are opened. However, if I try something like this:

Private Sub Form_Activate()
  DoCmd.Maximize
End Sub

or

Private Sub Form_Activate()
  DoCmd.Restore
End Sub

it has the effect of maximizing or restoring every open window, which isn't what I'm looking for.

Is there any way around this?

I'm using Access 2003.


回答1:


ΤΖΩΤΖΙΟΥ is 100% right when saying that either all are maximised, or none. If you really want to manage this issue, you'll have to read a little bit here (look at the code proposed and the way to call it), understand what is done, and eventually build your own solution depending on your needs.




回答2:


Access is an MDI (Multiple Document Interface) application, and this is how they work: either all sub-windows are maximized, or none.

What you need to do, is find a way to discover the dimensions of the Access application window, and then programmatically set the form's .InsideWidth and .InsideHeight properties. The Application object has a hwndAccessApp that probably can be used with some Windows API call to find out its width and height.

addendum

Thanks to Philippe Grondier for finding a relevant code sample, the general idea from the code sample is:

  • declare the following Win32 API elements:
    • struct Rect (Type Rect… in VBA)
    • const SW_SHOWNORMAL = 1 (for ShowWindow)
    • GetParent (given a hwnd, get its parent's hwnd)
    • GetClientRect (retrieve position and size from a hwnd)
    • IsZoomed (boolean; true if window is maximized)
    • ShowWindow (change the state of a window)
    • MoveWindow (to change the position and size of a window)
  • if your form is maximized (IsZoomed(frm.hWnd) = True), then restore it (ShowWindow frm.hWnd, SW_SHOWNORMAL)
  • get the MDI clients area from your form's hWnd (GetClientRect GetParent(frm.hWnd, rect))
  • use the rect data to change the position and size of your window (MoveWindow frm.hWnd, 0, 0, rect.x2-rect.x1, rect.y2-rect.y1)

(The above is basically the explanation of the code sample; I didn't copy-paste the code because I wasn't sure if the author allowed it).




回答3:


You can use MoveSize:

DoCmd.MoveSize 100,100

Further information: http://msdn.microsoft.com/en-us/library/aa141514(office.10).aspx




回答4:


There are a couple of options here: http://www.jamiessoftware.tk/articles/resolution.html

I used ADHResize in the past and it got the job done.



来源:https://stackoverflow.com/questions/217132/controlling-size-of-forms-in-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!