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.

If you enjoyed this post, subscribe for updates (it's free)

Wenn Du Lust auf schöne

Wenn Du Lust auf schöne Erotik hast und von tabulose Frauen, die einen Flirt für gewisse Stunden suchen, nicht lassen kannst, dann suche mal im Web unter dem Begriff Erotikkontakte. Du wirst erstaunt sein, wie schnell du geile Frauen für ein Blind Date finden wirst. Wenn du Probleme hast, sexy Girls einfach so anzusprechen, investiere einfach ein paar Euro in eine gute Partnervermittlung. Schneller aus du es dir je erträumt hast, findest Du einen Partner, mit dem du deine erotische Fantasien ausleben kannst. Es gibt sicherlich eine Menge Sexseiten auf denen man behaarte Frauen bumsen kann. Also, wo du geile Pornos sehen kannst, wo es die Frauen anal miteinander treiben. Aber egal, wenn Dir nach Arschficken ist oder du sonst was in richtig Porno magst, bist du hier wohl richtig.

gud

gud

Great Code

Nice Articles for beginners.

08054034588

Pretty code

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.

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.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.