Solved

How to open a form centered?

Posted on 2002-07-26
5
152 Views
Last Modified: 2010-05-02
How do I make sure a form opens in the center of my screen?  Thanks
0
Comment
Question by:InvisibleMan
5 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 7179872
Set the forms StartUpPosition to  'CenterScreen'
0
 
LVL 4

Accepted Solution

by:
ChenChen earned 25 total points
ID: 7179917
Two ways:
1. add these two lines in the Sub form_load:
    me.left=(screen.width-me.width)/2
    me.top=(screen.height-me.height)/2

2. set StartUpPosition property to 'CentreScreen'

0
 
LVL 3

Expert Comment

by:sanjaykattimani
ID: 7180046
Above 2 ways you can centre the screen,
Make sure that once you set the startupPosition property, you do not drag the window or change the position [that resets the startupPosition property]
0
 
LVL 2

Expert Comment

by:vbPhil
ID: 7180290
I agree with the above, but I also like to keep the form invisible, until it is sized and/or centered.

Set Visible = False

in the Form_Load() event

'Size it first if necessary...

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

Doevents
Me.Show

This makes sure all of the moving around is finished before the user sees it.

0
 

Author Comment

by:InvisibleMan
ID: 7181095
Can someone give me a function or sub I could call to make sure they open in center view?  Thanks. This way I can pass in a form.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now