-
Apr 20th, 2015, 03:15 PM
#1
Thread Starter
PowerPoster
Positioning a form right above the taskbar, but in the right corner?
Hi there everyone. Earlier I was working on a form that centers in the middle of the bottom of the screen above the task bar. It works awesome, and the kindergarten kids love being able to reach the buttons.
I was looking at another form, but wanted to put it above the task bar in the right corner.
I found this code to help put it in the corner...
VB Code:
Me.Left = (Screen.Width - Me.Width)
Me.Top = (Screen.Height - Me.Height)
This does put it in the corner, but it would be awesome if it was above the task bar.
Would any one know how?
Thanks!
-
Apr 20th, 2015, 03:41 PM
#2
Re: Positioning a form right above the taskbar, but in the right corner?
What you're looking for is an 'always on top' feature.
this may help you:
http://www.vbforums.com/showthread.p...-always-on-top
-
Apr 20th, 2015, 03:55 PM
#3
Thread Starter
PowerPoster
Re: Positioning a form right above the taskbar, but in the right corner?
That is awesome. I added the code to let it stay always on top. Would you know how I can make the form move just above the taskbar? Just case it will block out the clock/date/the show desktop button.
-
Apr 20th, 2015, 06:36 PM
#4
Re: Positioning a form right above the taskbar, but in the right corner?
You are making the assumption that the taskbar is always at the bottom of the screen. That is probably true for a vast majority of users, but it can be moved. There is an API (SystemParametersInfo) that can tell you what part of the screen is not used up by the taskbar and other toolbars. A rectangle (RECT) structure is returned and you can align your window to anywhere within that rectangle and be pretty assured you won't be overlapping anything important.
Suggest searching this forum for examples. Use this keyword in your search: SPI_GETWORKAREA
-
Apr 20th, 2015, 11:05 PM
#5
Re: Positioning a form right above the taskbar, but in the right corner?
Originally Posted by Justin M
Earlier I was working on a form that centers in the middle of the bottom of the screen above the task bar.
. . .
I was looking at another form, but wanted to put it above the task bar in the right corner.
You only needed to modify a single line in that earlier code in order to achieve what you want. You'll have to change this:
Code:
X = (MI.rcMonitor.Right - MI.rcMonitor.Left - nWidth) \ 2&
to this:
Code:
X = MI.rcMonitor.Right - MI.rcMonitor.Left - nWidth
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)
-
Apr 21st, 2015, 06:58 AM
#6
Hyperactive Member
Re: Positioning a form right above the taskbar, but in the right corner?
VB Code:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _ ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long Private Const SPI_GETWORKAREA As Long = 48 Private Type RECT lLeft As Long lTop As Long lRight As Long lBottom As Long End Type Private Sub Form_Load() Dim deskRECT As RECT Call SystemParametersInfo(SPI_GETWORKAREA, 0&, deskRECT, 0&) Me.Move (deskRECT.lRight * Screen.TwipsPerPixelX) - Me.Width, _ (deskRECT.lBottom * Screen.TwipsPerPixelY) - Me.Height End Sub
-
Apr 21st, 2015, 07:29 AM
#7
Re: Positioning a form right above the taskbar, but in the right corner?
In the OP's previous thread, SPI_GETWORKAREA was already deemed unsuitable because the OP appears to be using more than 1 monitors.
Originally Posted by Justin M
I use a high one myself when I code, but the projectors at school use lower resolutions.
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)
-
Apr 21st, 2015, 10:54 AM
#8
Re: Positioning a form right above the taskbar, but in the right corner?
Originally Posted by Bonnie West
That API applies to the primary monitor only, but GetMonitorInfo API can be used for other than the primary monitor. That API also can return the work area available but additional APIs needed to determine which monitor. A non-VB example exists on MSDN
-
Apr 21st, 2015, 11:33 AM
#9
Re: Positioning a form right above the taskbar, but in the right corner?
I also think that the mention of "projectors" does not mean that he has more than one connected at once but rather a general statement about the projectors used at the school. Of course it is possible that more than one is in use which if true does complicate things a bit, unless they are used in clone mode which would be the same to the program as just using a single screen.
-
Apr 21st, 2015, 07:20 PM
#10
Re: Positioning a form right above the taskbar, but in the right corner?
Originally Posted by LaVolpe
That API applies to the primary monitor only, but GetMonitorInfo API can be used for other than the primary monitor. That API also can return the work area available but additional APIs needed to determine which monitor.
Exactly. And that's the reason I offered "a more robust alternative".
Originally Posted by DataMiser
I also think that the mention of "projectors" does not mean that he has more than one connected at once but rather a general statement about the projectors used at the school. Of course it is possible that more than one is in use which if true does complicate things a bit, unless they are used in clone mode which would be the same to the program as just using a single screen.
I was assuming that Justin was using at least 2 output devices: a laptop (?) and a projector. Based on his statement that the projector's resolution was lower than his laptop's, I surmised that the projector wasn't just a clone of the main laptop display.
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)
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
|