Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize all forms 2

Status
Not open for further replies.

ineedhelplease

Technical User
Dec 18, 2002
18
US
I created an application that uses a form placed on the left hand side as a “Navigation Menu” and other forms to the right of the navigation form as body forms so that the screen looks much like that of an internet page with frames. I created code to be able to shrink the navigation form in width allowing more space for the body forms. How can I refresh all forms open so that they will resize and move without taking the focus from the current body form being used?
 
How are ya ineedhelplease . . . .

You'll have to do a little experimenting, but, just set the [blue]Top, Left, Width & Height[/blue] to their new values.
Do this in the same routine that shrinks the Navigation Form.

Only problem, in VBA the values are in units called [blue]twips[/blue], one twip = 1/1440 of an inch.

cal.gif
See Ya! . . . . . .
 
The problem is I do not know which body forms will be open. The navigation menu allows the user to select forms to open and update different things like account, institution, or investment information. All forms or only one may be open, and I would like to resize all the forms that are open while leaving the current form being updated with the focus.

If I try to resize a form that is not open I get an error. I have the code to resize and move a form but how can I have access determine only the open forms for resizing?
 
Take a look at the IsOpen function in Northwinds example database.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
OK ineedhelplease . . . .

[blue]PHV[/blue] has a good idea, but to extend it a little further, you need to loop thru the [blue]Forms Collection[/blue] executing your sizing code something like this:
Code:
[blue]Public Sub frmSizing()
   Dim frm As Form, Lft As Long, Top As Long
   
   For Each frm In Forms
      If frm.CurrentView > 0 Then [green]'Form not in design view[/green]
         If frm.Name = "[purple]FormName[/purple]" Then
            Forms(frm.Name).Top = TwipsFromTop
            Forms(frm.Name).Top = TwipsFromLeft
         ElseIf frm.Name = "[purple]FormName[/purple]" Then
            Forms(frm.Name).Top = TwipsFromTop
            Forms(frm.Name).Top = TwipsFromLeft
                           '
                           '
         ElseIf frm.Name = "[purple]FormName[/purple]" Then
                           '
                           '
         End If
      End If
   Next
                           
End Sub[/blue]
The only problem I see is if your forms are of different sizes. If this is the case, you have a fromidable task ahead of you figuring all the combinations. Espcially if the forms can be randomly open.

If as you say: [blue]all forms or only one can be open[/blue], then you'll have an easier go of it.


cal.gif
See Ya! . . . . . .
 
ineedhelplease . . . .

Forgive me ineedhelplease . . . . [purple]I've made an error here![/purple]
[blue]Top & Left[/blue] are not properties of forms, but of controls. Although the [blue]width[/blue] is, its not positional. So the code will fail with the properties given.

I'll see what else I can come up with for position.

cal.gif
See Ya! . . . . . .
 
You might need to take a look at the MoveWindow API. It will allow to size and position any window on demand.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
ineedhelplease . . . .

The best you can do is make a single blank form (that spans full) to hold the others as subforms (controls as far as the blank form is concerned). The you can use the Top/Left properties for positioning.

There is the side effect of having to work with the [blue]Visible Property[/blue] as well (initally all subforms will be hidden, save you navigator).

This also voids the code I gave you eariler as referencing is no longer the same.

Let me know if ya wanna continue with this!

cal.gif
See Ya! . . . . . .
 
Thanks CajunCenturion . . . .

In all my years I've never had to use it!

Perhaps you can fill us both in here?

cal.gif
See Ya! . . . . . .
 
The MoveWindow API redraws a window at a given top-left coordinate position, and at a given width and height. The following example simple repaints the entire window without resizing, using the window's current width and height. Using different values for height and width and/or top and left will move and/or resize the window.

This example repaints the entire Access background window (Window handle = hWndAccessApp), but the function will operate on the specific window you specify, such as Me.hWnd, or the window handle of another form.
Code:
GetWindowRect hWndAccessApp, lRct_WinPos
With lRct_WinPos
   lLng_WinWidth = .tLng_Right - .tLng_Left + 1
   lLng_WinHeight = .tLng_Bottom - .tLng_Top + 1
   MoveWindow hWndAccessApp, .tLng_Left, .tLng_Top, lLng_WinWidth, lLng_WinHeight, True
End With
In a module, you'll need the following declarations:
Code:
Public Type RECT
    tLng_Left                 As Long
    tLng_Top                  As Long
    tLng_Right                As Long
    tLng_Bottom               As Long
End Type

Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion . . . .

[blue]Excellent![/blue] . . . . Absolutely [blue]Excellent![/blue]

[purple]I've never had the need to use API much[/purple] and at best, I would be rusty since I last used it in code. [blue]The schema here is certainly one for the books.[/blue]

I don't know if the post origiator could appreciate it as much as I, but I hope they return. They need to see this!

Nice piece of work!

cal.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top