Center your form on the screen

Level:
Level1

Below you will find only four lines of code. But these four lines of code allow you to do something that would take hundreds of lines of code using a language such as C++. This source sample demonstrates how you can use Visual Basic's built in property called Screen to grab information about, wouldn't you know it, the screen that your application is running on. What this code does is queries the screen width and height. It then subtracts your forms width and height and divides it by two so you can put it in the middle.

To use this source code simply create a new VB project. Open the code for your form and add the following source to it.

  1. With Form1
  2.     .Top = (Screen.Height - .Height) / 2
  3.     .Left = (Screen.Width - .Width) / 2
  4. End With

You will notice that we are using the With construct that VB provides. All this does is causes Form1 to be implied before any . found in the code.

Note: The source for this was found at DreamVB which is no longer online.

Good code. I'd find it by

Good code. I'd find it by myself, when experimenting with Screen object.
What is good - it will pose the form on the center on any screen resolution - so, the form will appear in center and on a small netbook, and on a big screen of a PC.

This is often significant.

This is often significant. Sole stare upon every single written copy and we are wordless. We are precisely attracted to this type of traits. Every appreciate yer lay, and number your precious time while in this. Please keep control. They're same handy contact information study which will provide your receiver a very invisible acumen.
king memory foam mattress

So good. ... Keep working...

So good. ... Keep working...

do you just copy & paste this

do you just copy & paste this coding?

Awesome

You are right about how difficult this would be in C++. I can't even imagine! Well I can but yeah...

Nice

Nice Thanks
asp.akhilesh@yahoo.co.in

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options