Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Center a frame

Posted on 1998-09-12
10
Medium Priority
?
189 Views
Last Modified: 2010-04-30
How do I center a frame on a form?  My form will be set to maximized, so I need the frame (and all of its contents to be centered).  Also, a frame and all of its contents (text boxes, labels, etc.) are considered one entity, the frame, right?  Thanks.
0
Comment
Question by:regent
  • 4
  • 3
  • 3
10 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 280 total points
ID: 1434572
Frame.Left = (Form.Width / 2)-(Frame.Width / 2)
Frame.Top = (Form.Height / 2)-(Frame.Height / 2)

Regards,
Viktor Ivanov
0
 

Author Comment

by:regent
ID: 1434573
Where to a need to put this code?
0
 

Author Comment

by:regent
ID: 1434574
Sorry, where do I need to insert this code?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:wj7ster
ID: 1434575
You have to put the code in the Form_Resize event procedure.

Another way of doing this is to use the 'Move' method.  This is essentially the same as the code provided by victornet, but is more preferable since it does it all in one command, thus slightly faster.

On Error Resume Next
Frame1.Move (Form1.ScaleWidth - Frame1.Width) / 2, _
            (Form1.ScaleHeight - Frame1.Height) / 2
On Error GoTo 0

With this method there is two more optional parameters, [Width] and [Height] in order to resize the frame in this instance.

Remember to put some error handling as well, since when you minimize the form, some property settings might evaluate to invalid results.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1434576
Actually no error can occur since this is a simple procedure...
Put the code in the form's resize event

0
 

Author Comment

by:regent
ID: 1434577
Thank you very much!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1434578
No prob ;-)
0
 
LVL 2

Expert Comment

by:wj7ster
ID: 1434579
A Further note:

Use the 'ScaleWidth' and 'ScaleHeight' properties of the Form, rather than just the 'Width' and 'Height' properties, since this does not take into account the Form's caption/Title bar height and the borders since a user can set these to some absurd values if he wants. (You can retrieve all of these settings by using the GetSystemMetrics API call if you insist on using just the 'Width' and 'Height' properties.)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1434580
Yeah, that might be a point....If you want the title bar to be included then use Width/Height
otherwise if you only need the Form's client area use ScaleWidth/ScaleHeight

About using the GetSystemMetrics, I think you don't need to get much into APIs to do centering of the form....

Regards,
Viktor Ivanov
0
 
LVL 2

Expert Comment

by:wj7ster
ID: 1434581
Victor,

You are right about GetSystemMetrics, I just wanted to point out that there is an alternative and even trying to be a little sarcastic there to emphasize the 'over kill' of using the API.

Regards

Wille Sevenster
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question