Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
This code is a great way to create a toolbar that ...
Author:
Bryan King
E-mail:
Click to e-mail author
Submitted:
3/15/2002
Version:
VB5
Compatibility:
VB5, VB6
Category:
Forms
Views:
15675
This code is a great way to create a toolbar that hides just above the desktop until the cursor is positioned near the top of the screen which makes the toolbar drop down. Moving the cursor off the form makes the form hide itself again.
Declarations:
' THIS CODE WAS WRITTEN IN VISUAL BASIC 5 'the codes to read the screen size and 'GetCursorPos were found on the internet. 'I forget where but if it is your code, please email me and 'I will add credit for your work. 'This code is a great way to create a toolbar that hides 'just above the desktop until the cursor is positioned near 'the top of the screen which makes the toolbar drop down. 'Moving the cursor off the form makes the form hide itself again. 'With a little work and understanding, this 'can be modified to have the form hide to the right or left 'of the desktop instead of the top. As far as I know, you can use 'this code any way you want to, it's free. 'The code in the Timer1 event handler was created by me. 'It took a lot of trial and error, and some math, but it works. 'If you find this code useful or have questions please email me: 'bryanwks@hotmail.com 'Also, if you know of an easier way to do this, please email me. 'general declarations Private Type POINTAPI X As Long Y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Code:
Private Sub Command1_Click() Me.Top = 0 - Me.Height 'hide the form just out of sight above the desktop 'out of sight until needed. MsgBox "Hi" 'replace with your code 'This can also be used to shell external programs End Sub Private Sub Timer1_Timer() 'declare the variable. Dim ptAPI As POINTAPI 'pass the cursor position to the new variable. GetCursorPos ptAPI 'if the cursor is within 5 twips of the top of the screen. If ptAPI.Y < 5 Then 'bring the form down so that the top of 'the form aligns with the top of the screen. Me.Top = ScreenTop 'if the cursor leaves the form, then hide the form 'above the desktop again. 'The Val(ptAPI.Y * 15) code was necessary because the variable ptAPI.Y 'is given the cursor position in pixels and I was using twips when 'calculating the Height and Width of my forms. 'So Val(ptAPI.Y * 15) simply converts the cursor position from 'pixels to twips since the sizes are different in pixels than 'they are in twips. The entire program needs to work by the 'same set of rules. ElseIf Val(ptAPI.Y * 15) > Me.Height Then 'check to see if the cursor goes below the form Me.Top = 0 - Me.Height 'hide the form until needed. ElseIf Val(ptAPI.X * 15) < Me.Left Then 'check to see if the cursor goes to the left of the form Me.Top = 0 - Me.Height 'hide the form until needed. ElseIf Val(ptAPI.X * 15) > Me.Left + Me.Width Then 'check to see if the cursor goes to the right of the form Me.Top = 0 - Me.Height 'hide the form until needed. End If End Sub Private Sub Form_Load() 'begin code to read the screen size Dim SX As Long Dim SY As Long SX = Screen.Width / Screen.TwipsPerPixelX SY = Screen.Height / Screen.TwipsPerPixelY 'end code to read the screen size Me.Left = (Screen.Width - Me.Width) / 2 'center the form horizontally on the screen Me.Top = 0 - Me.Height 'hide the form just out of sight above the desktop 'out of sight until needed. 'put the current time into Label1 Label1.Caption = Format(Now, "h:mm:ss am/pm") End Sub Private Sub Timer2_Timer() 'update the current time into Label1 Label1.Caption = Format(Now, "h:mm:ss am/pm") End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement