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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine the insideWidth of a form?

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I have a split form and via the Activate event (tried it under the Open event) I maximize the form. However, the InsideWidth property of the form (tested on events: Open, Load, Activate, Current, Resize) always returns the value of the InsideWidth when the form is not maximized. Note that once the form is displayed and I select a button to check the InsideWidth, it now shows it correctly.

So, how do I get the correct InsideWidth. Note that all values are correct when the form is a simple form rather than a split form.

I'm trying to center the controls when the form is opened and resized. Works fine with simple form but not with split form.
 
Howdy FancyPrairie . . .

Considering it takes a finite amount of time for a form to maximize, it can only take the same amount of time to set [blue]InsideWidth/InsideHeight[/blue] proper. Unfortunately this time is well past the [blue]On Current[/blue] event. So we need a mechanism to wait. Enter the [blue]IsZoomed[/blue] API.

Special Note: you must use the maximize command as in the following code. The code will hang if you try to detect a form that maximizes normally without the command. I Tested in the [blue]On Open[/blue] event:
Code:
[blue]   DoCmd.Maximize [green][b]'MUST USE![/b][/green]
   
   Do Until IsZoomed(Me.hwnd) > 0
      DoEvents
   Loop
   
   Me.[purple][B][I]YourTextboxName[/I][/B][/purple] = Me.InsideWidth[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
FancyPrairie . . .

So sorry ... I forgot to post the API. In the [blue]declarations section[/blue] a module in the modules window, copy/paste the following:
Code:
[blue]Public Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Integer[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I'm not able to get it to work. The code never exits the loop. I've tried putting the code in several events (open, load, activate, resize).

Note that it does work when the Default View property is set to "Single Form", but does not work when the Default View is set to "Split Form".
 
FancyPrairie . . .

Best I can think of is to make use of the forms timer. In the [blue]On Open[/blue] event:
Code:
[blue]   Me.TimerInterval = 50[/blue]
In the [blue]On Timer[/blue] event:
Code:
[blue]   Me.[purple][B][I]YourTextboxName[/I][/B][/purple] = Me.InsideWidth
   Me.TimerInterval = 0[/blue]
Perform your testing.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
FancyPrairie . . .

I don't have 2007/2010 to perform any direct testing but perhaps there's the eqivalent of assigning a [blue]section width[/blue] object (since the form is split) and checking InsideWidth that way. However I doubt it.

GoodLuck with this ...

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top