Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to get the form width and height

How to get the form width and height

How to get the form width and height

Easy question: How to get the form width and height?

I don't mean thisform.width or thisform.height
These properties don't return the dimensions of the form as it was designed. They return the dimensions at runtime.

Example: I create a form 1400 pixels wide and compile the program to an EXE.
When the EXE runs on a computer with a smaller monitor, let's say 1280 wide, the form is truncated to fit on the smaller monitor and objects on the right site become invisible. thisform.width returns 1280.

But I want the original size so I can programmatically scale down to 90% or so, 1400*90%=1260 and not 1280*90%.
So I need the value of 1400 in this example. Is that possible with a general function?

RE: How to get the form width and height

That doesn't sound like the default behavior. I think you already have code that's fiddling with the size of your form.

I just create a form, set Height to 2000 (which is more than fits on my monitor) and put a button on it with this code in Click:

CODE -->

WAIT WINDOW ThisForm.Height 

When I run the form, it runs over beyond the bottom of my screen and clicking the button displays 2000. Next, made the form modal, created a project, and added the form. Built an EXE and run it. Same behavior.

Are you using a framework that might have code that checks whether a form fits?


RE: How to get the form width and height

Thanks Tamar. This behavior seems to be corrected in VFP9.
My question is about VFP6. Still my favourite. (Desktop/Modal)

RE: How to get the form width and height

I don't think VFP6 differs in that aspect, I think you have set your form.WindowState to maximized.

If you want to maximize your form but first want to know the original dimensions, don't set it maximized at design time already. When it starts in normal WindowState, you get the design sizes and can scale it up. You can set the WindowState to maximized late as the form does show late, you can still adjust the form content in init. For scaling you still need to know the maximized size, which you get either by simply maximizing the form after you read out the design dimensions or use SYSMETRIC(). I think VFP6 has a subset of the SYSMETRIC information available to VFP9.

VFP6 has so many bugs, even with SP5, that I really wonder why you didn't upgrade, I can only assume you mean VFP6 is still your favorite in comparison to alternative languages or tools like Access. You can't dislike a later VFP version as it always is fully compatible and just offers more, not less. Anchroing would be the best solution for your case, for example, and that's introduced in VFP9.


RE: How to get the form width and height

No the form is not maximized.
By the way, even in the Load and Init methods thisform.width returns the monitor width and not the designed width.
Of course somewhere in de EXE, in forms.scx -> form properties, is the right value stored. Just don't know yet how to access this at forms run time.
On monitors as big or bigger than designed on, the return value is correct.

RE: How to get the form width and height

Are you sure that's VFP shrinking the form or your graphics card driver or some setting of it.

I do remember I used off screen form coordinates for things like hiding a form in visible state, so you can use off screen coordinates and thus also sizes. I don't think your problem is in VFP.

I trust you get higher width/height already in Load, but that doesn't come from VFP6 alone.

Is this a single form application the user has maximized and the quit in the maximized state? Then it will get maximized at next start. That's retained in foxuser.dbf.


RE: How to get the form width and height

Chris, do you have VFP6? If so, try it.


I trust you get higher width/height already in Load, but that doesn't come from VFP6 alone.
Or don't you understand the question? I get a lower value if the exe is run on a computer/screen with a lesser resolution. Not higher. That is the problem. On computers with the same or higher resolution the right value is returned because the form fits but on older monitors, that often has lesser pixels that smaller width value is returned and the form is truncated. I just ask a way to get the designed width value not the truncated width (in VFP6)

Example. I show it in code now, but normally I use the form designer. Makes no difference.
In this example I create a form wide 7000. That is bigger than most monitors can handle.
If you run it on any computer with a resolution smaller than 7000, VFP6 will return the current monitor width as answer.
Like 1366. And hitting the Adjust button makes the form 136 wide. On a 1920 Full HD monitor scaled at 125% it will return 1536.
If you run this code in VFP9 it will return 7000, the designed value as Tamar mentioned. The Adjust button makes the form 700 wide.
The question is how to get 7000 in VFP6 as thisform.width return value. Or in any other way.

Quote (VFP6)

PUBLIC oform1


*-- Form: form1 (e:\vfp6test\tektips.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 09/17/22 04:41:03 PM
DEFINE CLASS form1 AS form

Top = 0
Left = 0
Height = 250
Width = 7000
Desktop = .T.
DoCreate = .T.
Caption = "Form1"
WindowType = 1
Name = "Form1"

ADD OBJECT command1 AS commandbutton WITH ;
Top = 48, ;
Left = 348, ;
Height = 49, ;
Width = 145, ;
Caption = "Show width", ;
Name = "Command1"

ADD OBJECT command2 AS commandbutton WITH ;
Top = 120, ;
Left = 348, ;
Height = 48, ;
Width = 145, ;
Caption = "Adjust form", ;
Name = "Command2"



PROCEDURE command1.Click

PROCEDURE command2.Click

*-- EndDefine: form1

RE: How to get the form width and height

Quote (JackTheC)

Or don't you understand the question?

I do understand the implication of the form truncated to a lower than designed size, but as I said I don't believe VFP does that. Either it's your graphics card, driver or software, or it's because a user closes the app with maximized window, which is retained in foxuser.dbf and so (yes, already in load) you don't see the design widht/height but something smaller.

I don't know what exactly happens, but I'm quite confident that's not done by VFP.

Nevertheless, you get what you get.

One last try without resorting to opening the SCX file and fetching it from some property memo, would be if you explicitly set thisform.windowstate=0 in the form.init() and then see what thisform.width and thisform.height become.


RE: How to get the form width and height

Thanks Chris, but thisform.windowstate=0 in Init or Load makes no difference.
Have you been able to run the above code in VFP6 (or maybe 7 or 8 dont know that).

RE: How to get the form width and height

No, but does it matter?

Taken for granted you don't get at the design dimensions from the form object, you would need to grab it from the scx or vcx. That's also within the EXE, so it should be doable to USE yourform.scx.
The third record will have form properties including width and height in the Properties memo.

It's still bugging me, I've never had any automatic resizing or truncation at all. How does it work, actually, is the form shrinked or is it actually truncated? If you move it, will the invisible part become visible or is it non-movable?

You're sure there is no setting like "center windows in desktop", "shrink forms to fit in desktop" in your graphics driver or some automatism like that? I remember a wide spread feature of graphics drivers was the feature to open an application in the current display, the display your mouse is in, so there's no surprise double clicking an application icon starts it on another display. And that could easily be extended to care for the form size, outside of the scope and behaviour of what VFP itself does.

The dpi dependent size is normal, you get that as scale factor, VFP only works correctly on a 100% scale factor with many things, even things like the look of tabs of pageframes is determined by that, IIRC the font size will not fit tab captions.


RE: How to get the form width and height

I can tell you this happens on every computer and every OS (7,8,10,11) with VFP6. I tested.
But not in VFP9. So this is a thing in VFP6 that was changed in VFP9 (or 7 or 8)

If you take a look at the code above, you can see every setting. Running this program in VFP6 returns pixel width of current computer/monitor and returns 7000 in VFP9.

You cannot open the SCX in a running form. I want to determine the form width within a running form.
Of course I can make an extra property in the form holding a copy of the form dimension but that means that every form design change should also be maintained in that property. You know Murphy's law.

RE: How to get the form width and height

Quote (JackTheC)

You cannot open the SCX in a running form.
At design time, yes. I talked about the EXE. I said

Quote (myself)

That's also within the EXE, so it should be doable to USE yourform.scx.
When you do a scx that's in the EXE ou should still be able to USE it, also you could copy it or use it before running it. You don't have to do anything that's impossible, but you should be able to get at what you want if you simply think of alternatives. You could also just build a table of form dimensions to lookup the design dimensions and feed it at design time - with a projecthook, which extracts this information when building, for example. You can STRTOFILE(FILETOSTR("yourform.scx"),"currentform.scx") to enable using the copy of the SCX and there are a ton of further things you could do.

One more thing which also won't bring back the design dimensions is using thisform.ResetToDefault("width") (and "height"), because the design dimensions are not the default values, the default values ar that of a base form class, just 375x250 pixels. If you get what you say you don't have a chance to get at the design dimensions in the form itself as it was at designtime, these values are lost and so you have to get them from the scx or meta data you maintain about the forms.


RE: How to get the form width and height

@JackTheC, curious why you stay in VFP 6. Since then, there were tons of bug fixes, as well as the introduction of IntelliSense and some new tools and so much good stuff. I'd hate working in VFP 6 now.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close