$4.95 Hosting 782x40

Visual Basic Code Snippets #3

Posted by admin on Friday, Sep 11th, 2009 at 11:27 am
Filed Under: Programming and Visual Basic

In this next update I’ll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Forms.

Center a Form on the Screen

Compatibility: Win. 98-XP

Add the following code into a module within your project…

Public Sub Form_Center(Frm As Form)
'Usually used in form_load
Frm.Left = Screen.Width / 2 - Frm.Width / 2
Frm.Top = Screen.Height / 2 - Frm.Height / 2
End Sub

Add a form named Form1 and add the following code wherever you want the code to execute…

Call Form_Center(Form1)

Center Form at a Given Point on the Screen

Compatibility: Win. 98-XP

Add the following code into a module within your project…

Public Sub Form_CenterAt(Frm As Form, X As Integer, Y As Integer)
'X: X coordinate to center form at
'Y: Y coordinate to center form at
'Example...
'Form_CenterAt me, screen.width/2, screen.height/2
Frm.Left = X - Frm.Width / 2
Frm.Top = Y - Frm.Height / 2
End Sub

Add a form named Form1 and add the following code wherever you want the code to execute…

Call Form_CenterAt(Form1, screen.width/2, screen.height/2)

Visual Basic Code Snippets #4

Comments (3)

  1. [...] Visual Basic Code Snippets #3 [...]

  2. [...] Visual Basic Code Snippets #2 Visual Basic Code Snippets #3 [...]

  3. [...] Basic Code Snippets #1 Visual Basic Code Snippets #2 Visual Basic Code Snippets #3 Visual Basic Code Snippets [...]

Leave a Reply

You must be logged in to post a comment.

Support Mr. Eskew! Buy a Shirt!

QueryVegas.com Tweets