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

How to get the form width and height

Status
Not open for further replies.

JackTheC

Programmer
Feb 25, 2002
324
NL
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?


 
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?

Tamar
 
Thanks Tamar. This behavior seems to be corrected in VFP9.
My question is about VFP6. Still my favourite. (Desktop/Modal)
 
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.

Chriss
 
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.
 
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.[tt][/tt]

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

VFP6 said:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


**************************************************
*-- 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 Init
messagebox('I'+str(thisform.width))
ENDPROC


PROCEDURE Load
messagebox('L'+str(thisform.width))
ENDPROC


PROCEDURE command1.Click
messagebox(str(thisform.width))
ENDPROC


PROCEDURE command2.Click
thisform.width=thisform.width*0.10
ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
 
JackTheC said:
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.

Chriss
 
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).
 
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.

Chriss
 
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.
 
JackTheC said:
You cannot open the SCX in a running form.
At design time, yes. I talked about the EXE. I said

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

Chriss
 
@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.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top