Recent Posts

Sunday, June 22, 2008

VB 6.0 Putting the form to center of the screen/ Maximising the form

Public Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long


Public Sub MaximiseForm(frm As Form)
On Error GoTo SubError

Const SubName = "Maximise"

Dim ScreenWidth As Long
Dim ScreenHeight As Long
Dim ScreenLeft As Long
Dim ScreenTop As Long
Dim DesktopArea As RECT

Call SystemParametersInfo(SPI_GETWORKAREA, 0, DesktopArea, 0)

ScreenHeight = (DesktopArea.Bottom - DesktopArea.Top) * Screen.TwipsPerPixelY
ScreenWidth = (DesktopArea.Right - DesktopArea.Left) * Screen.TwipsPerPixelX
ScreenLeft = DesktopArea.Left * Screen.TwipsPerPixelX
ScreenTop = DesktopArea.Top * Screen.TwipsPerPixelY

With frm
.Top = ScreenTop
.Left = ScreenLeft
.Height = ScreenHeight
.Width = ScreenWidth
End With

SubExit:
Exit Sub

SubError:

ShowErr App.Title + " " + SubName
Resume SubExit

End Sub

'Puts the Form in the center of the Screen

Public Sub CentreForm32(frm As Form)
On Error GoTo SubError

Const SubName = "CentreForm"

Dim ScreenWidth As Long
Dim ScreenHeight As Long
Dim ScreenLeft As Long
Dim ScreenTop As Long
Dim DesktopArea As RECT

Call SystemParametersInfo(SPI_GETWORKAREA, 0, DesktopArea, 0)

ScreenHeight = (DesktopArea.Bottom - DesktopArea.Top) * Screen.TwipsPerPixelY
ScreenWidth = (DesktopArea.Right - DesktopArea.Left) * Screen.TwipsPerPixelX
ScreenLeft = DesktopArea.Left * Screen.TwipsPerPixelX
ScreenTop = DesktopArea.Top * Screen.TwipsPerPixelY

frm.Move (Screen.Width - frm.Width) / 2 + ScreenLeft, (ScreenHeight - frm.Height) / 2 + ScreenTop

SubExit:
Exit Sub

SubError:

ShowErr App.Title + " " + SubName
Resume SubExit

End Sub

Related Posts by Categories




No comments:

Post a Comment