dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Nov 17, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Yet Another CenterForm Routine

In the April 1997 issue of VBPJ, you published a tip called "Consider the Taskbar When Centering Forms." You can center forms more easily with the SystemParametersInfo API call:
 
Private Declare Function _
	SystemParametersInfo Lib "user32" Alias _
	"SystemParametersInfoA" (ByVal uAction _
	As Long, ByVal uParam As Long, R As Any, _
	ByVal fuWinIni As Long) As Long
Private Type RECT
	Left As Long
	Top As Long
	Right As Long
	Bottom As Long
End Type
Private Const SPI_GETWORKAREA = 48
Public Sub CenterForm(frm As Form)
	Dim R As RECT, lRes As Long, 
	Dim lW As Long, lH As Long
	lRes = SystemParametersInfo( _
		SPI_GETWORKAREA, 0, R, 0)
	If lRes Then
		With R
			.Left = Screen.TwipsPerPixelX * .Left
			.Top = Screen.TwipsPerPixelY * .Top
			.Right = Screen.TwipsPerPixelX * .Right
			.Bottom = Screen.TwipsPerPixelY * .Bottom
			lW = .Right - .Left
			lH = .Bottom - .Top
			frm.Move .Left + (lW - frm.Width) \ 2, _
				.Top + (lH - frm.Height) \ 2
		End With
	End If
End Sub
Nicholas Sorokin
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date