Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

look for advices in resizing forms

I design my forms according to my screen resolution and dimentions. but when I install the same project on other PC I find that the forms and its controls are not at the same location as mine because of the diffrences of screen resolution and settings. are there any common way or advices to solve the situation?
if there is a code , please show it

1 Solution
If you're just after form position, use the code...

Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2

or replace Me with any form you need... or put it in a sub like..

Public Sub CenterForm(frmCenter As Form)
frmCenter.Left = (Screen.Width - frmCenter.Width) / 2
frmCenter.Top = (Screen.Height - frmCenter.Height) / 2
End Sub

then you can do..

CenterForm Me  or..
CenterForm frmMain or whatever you need to center

GouGouAuthor Commented:
thanx for your answer.
But this is OK for the form. my problem is about the controls' position which may being cut in large screen settings for example 640*480 is completely different than 1024*768 and so on
Best practice is to design for the smallest screen your program will run on.  Typically, this is 800x600, but if your customer has some 640x480 workstations, then you should try to accomodate them by designing for this size.  If you find you have too many controls to fit the smaller size, then you may have to use a tabbed dialog or other space saver to free up onscreen real estate.  

There are resizers available as third party controls, but they can result in some odd looking screens.  
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

I agree 100% with PaulHews....I ALWAYS design the Application for the Absolute SMALLEST resolution that will EVER be used for the program.  That way I am sure about the placement of controls, and the real amount of available space on the screen.  That also forces the developer to be realistic about the number of controls that are placed on any one screen.

That does NOT mean, however, that I do not attempt to convince the end users that it is in their own best interest to seriously consider upgrading CRTs to a higher resolution, if at all possible.

I agree with the statements so far.

But one further consideration if your forms are covered in things like pictures charts or lists these can be easly resized to fit the form. I typically design to types of form (with respect to your problem).

1) Fixed forms, that cannot be resized these typically contain many textboxes and combos.

2) Full screen forms, these typically will resize but not always.  these forms tend to consist of list controls, grids, pictures, charts and treeviews etc.

The Forms resize event is used to control the size of the list portions.

In theory you could make all forms resizeable but often there is absolutley no need unless you like blank spaces.
I'm not sure how you get the screen resolution from the computer but there is a way. Check for the users resolution and resize and move all of your buttons etc. throught the code.
The best solution for this will be something like this:
RELATIVE POSITIONING of all controls in the form!!
For this, u can use SCALE command to decide corner coordinates. I generally use upper left as -1,-1 and lower right as 1,1 so that centre is 0,0. Now, place ur controls on the form always with respect to this system. Because corners will be adjusted automatically runtime, remianing distances will also get adjusted giving no problems of positions, and about sizes also you should decide some scale depending on the corner positions of forms. This way ur form will be displayed same on any machine!! Hope this helps u

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now