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!

Position Form Just Off Center

Status
Not open for further replies.

gbcpastor

Programmer
Jun 12, 2010
77
US
I need to position a small message form on screen. I want to center it left to right but I want it 1" down from top of screen regardless of what computer I run the program on. Any ideas?
 
Well, I don't think you're going to get that...
Because 1" is different on different monitors. For instance, I'm using a 43" 4K monitor with a vertical resolution of 2160 pixels. On my laptop, I have a 1920 x 1080 resolution. That means the pixels in both monitors are quite different in size, and it will be the same for others.

What you will be better off doing is figuring out exactly which row of pixel you want your message to be "below" rather than saying 1".

Then you just set This.Top = <some number of pixels>

Which are counted from the top of the WINDOW down.
This gets tricky, but give that a go first.

The left to right can be set separately, that's an easier matter that Im sure you can work out.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
SYSMETRIC(2) will get you the height of the screen in pixels. So you need a way of converting pixels to inches. The actual conversion ratio will be a function of your monitor's resolution. Sorry I can't tell you how to get that. No doubt someone will know.

But I echo what Scott said. Don't design your screens in inches. Think in pixels. Monitors vary enormously in size. You never know when you might come up against one where an inch is a substantial portion of the height. I would suggest you use SYSMETRICS(2) to get the height of your screen in pixels; then position the top of your message form, say, one third of that number of pixels down from the top of the screen.

Keep in mind too that the form's Top property is relative to your app's main window, not the physical screen. If your main window was positioned in, say, the bottom corner of the physical screen, would you want your message to appear in a fixed position relative to the screen or the window?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
My suggestion here, having done a lot of this lately (and dynamically placing pop-up windows on the screen), you are much better off working relative to the MAIN window, and then adjust within your form, particularly if you're not running in a full screen mode, and don't forget, users do all kinds of craziness, let alone all the screen size issue that we've mentioned. I suggest, always work in Pixels, and consider screen variation in size.

The "LEFT" property is also like the "TOP" property which is how VFP positions things. It will be just as relative to position in screen width and mainform positioning as the TOP issue will be, though centering generally overall is easiest. I'm not sure why you don't just go with a center screen if this is some kind of message box... as you mention. Why not just use MESSAGEBOX()?


Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Scott, there is autocenter as form property. And that's the easiest thing to use to get a starting point to then add an offset.

If you set Form.Autocenter T. you get the top and left set automatically. This happens before Show finally shows the form, so you can adjust top in the Show method, perhaps also in the form.Init (I won't try that right now, but it's not a big thing to try at two places), which would only occur once and therefore is better suited to make add an offset one time.

ONce you know the dpi you can know how many pixels are an inch, but dimensions of screens differ a lot and on tablets with merely 4x3" you might move a 1" high message right to the bottom display edge.

In regard to centering on the desktop you simply make it a top level form.

Bye, Olaf.
 
Hi Olaf,
I'm not the OP, was trying to steer him into it, but your point is interesting about starting from center. I actually don't agree with that based on some dynamic positioning I did, where their offsets were not centralized, and in fact are quite scattered (not random, but scattered). But for his message box purpose (which I still think he's over thinking), keep it simple.


Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
I think there's enough good information here to make it happen. As for the messagebox() that's too generic. Not sure how you control things like Font Size and Position of the Box and so on.

Thanks folks, what a great fount of knowledge.
 
Scott, what you seem to have experienced is the slight offset VFP adds to each nistance of the same form to let a series of forms appear slightly moved down and right, then stsarting back at the top when the next form would appear too much to the right or bottom.

But that doesn't happen with autocenter.

Bye, Olaf.
 
Olaf,
Nope nope nope.

I have tried this on the same form, with lots of re-sizes with MAIN.SCX as the control where all other forms "live". I have sized it differently and tested on different monitors and many resolutions.
HOWEVER, it's based on the calling control. Where I consider the full size of the form, then where the form inside main is, then where the control is, then add a specific off-set based on that control. It works perfect every time. The code for that is here:

Code:
DO FORM VFACILITYNAV.SCX WITH BINTOC(FACILITY.COMPANYID), ALLTRIM(This.Name), This.Left+ThisForm.Left+This.Width, This.Top+ThisForm.Top+This.Parent.Parent.Top TO lnGetFacility

This is that magic pop-up form that you helped me with in getting the mouse move to position the record pointer, and then single-click.

Within the VFACILITYNAV.SCX the init is:

Code:
LPARAMETERS lnCompanyID, lcTestCity, lnLeftWindow, lnTopWindow
*
This.Left = lnLeftWindow+20
This.Top = lnTopWindow+50

Which provides an addition based on the control size where the MouseEnter occurred in the first code block.
Then we only care about the relative position of the current window to the current control, and an offset.

I think, I'm starting to get good at this again. :)


Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."[hammer]
 
All this for nothing? Autocenter automatically centers a form. To what it centers just depends on whether it is a for in screen, in a top level form (both child types) or a standalone desktop form.

You are talking about positioning a form to whatever reference position. In regard of centering within the desktop (the current display desktop) there is really nothing to do but set autocenter. You don't pass in any position for that matter. So this is a totally different situation than you talk about. Finding out a correct shift can be problematic. You often will need OBJTOCLIENT() for that and not what you did with the control position plus its form position and a parent top position. We're not talking about positioning right beside a button calling the form, we talk of center position. There is a property for that, it is called AUTOCENTER, AUTO CENTER. Got it?

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top