-
Mar 22nd, 2015, 03:51 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Postion a form on the middle of the screen right above the task bar?
Hi there folks. I am looking for a simple way to center the form in the middle of the screen.
I used this code to center it.
Me.Move Screen.Width - Me.Width, (Screen.Width / 2) - (Me.Width / 2)
What I would like to do is position it right above the task bar. I am working on a prog for kindergarten students, and if the form was on the bottom, it would much easier for them to reach the buttons.
Would anyone know how to lower it? Thanks a lot!
-
Mar 22nd, 2015, 09:35 AM
#2
Re: Postion a form on the middle of the screen right above the task bar?
Import the clsGetWorkArea.cls class module in this zip file to your VB6 project and then add the following code to your Form's Load event:
Code:
Private Sub Form_Load()
With New clsGetWorkArea
Move (Screen.Width - Width) * 0.5!, .WorkAreaHeight - Height
End With
End Sub
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Mar 22nd, 2015, 10:14 AM
#3
Re: Postion a form on the middle of the screen right above the task bar?
You can also use the sysinfo control to get this info using the workareaheight and workareawidth
-
Mar 22nd, 2015, 10:24 AM
#4
Thread Starter
PowerPoster
Re: Postion a form on the middle of the screen right above the task bar?
Thank you both for your help!
Would the code that Bonnie posted work for any resolution? I use a high one myself when I code, but the projectors at school use lower resolutions.
-
Mar 23rd, 2015, 02:30 AM
#5
Re: Postion a form on the middle of the screen right above the task bar?
Originally Posted by Justin M
Would the code that Bonnie posted work for any resolution? I use a high one myself when I code, but the projectors at school use lower resolutions.
Here's a more robust alternative:
Code:
Option Explicit 'In a Form
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type MONITORINFO
cbSize As Long
rcMonitor As RECT
rcWork As RECT
dwFlags As Long
End Type
Private Declare Function GetMonitorInfoW Lib "user32.dll" (ByVal hMonitor As Long, ByRef lpmi As MONITORINFO) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As Long, ByRef lpRect As RECT) As Long
Private Declare Function MonitorFromWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal dwFlags As Long) As Long
Private Declare Function MoveWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, Optional ByVal bRepaint As Long = -True) As Long
Private Function MoveToBottomCenter(ByVal hWnd As Long) As Boolean
Const MONITOR_DEFAULTTONEAREST = &H2&
Dim X As Long, Y As Long, nWidth As Long, nHeight As Long
Dim MI As MONITORINFO, R As RECT
MI.cbSize = LenB(MI)
If GetMonitorInfoW(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), MI) Then
If GetWindowRect(hWnd, R) Then
nWidth = R.Right - R.Left
nHeight = R.Bottom - R.Top
X = (MI.rcMonitor.Right - MI.rcMonitor.Left - nWidth) \ 2&
Y = MI.rcWork.Bottom - MI.rcWork.Top - nHeight
MoveToBottomCenter = MoveWindow(hWnd, X, Y, nWidth, nHeight)
End If
End If: Debug.Assert MoveToBottomCenter
End Function
Private Sub Form_Load()
MoveToBottomCenter hWnd
End Sub
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Mar 23rd, 2015, 07:03 AM
#6
Frenzied Member
Re: Postion a form on the middle of the screen right above the task bar?
Originally Posted by Bonnie West
Here's a more robust alternative:
Bonnie West always answers on an elegant way. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|