Jumat, 11 November 2011

[VB 6.0] Mouse Hover Button

Posted by b_agoy 04.37, under | No comments


Mouse hover ini digunakan untuk mengetahui apakah kursor mouse kita ada di suatu kontrol tertentu atau tidak. Sebenarnya tidak hanya dapat diterapkan pada kontrol button saja namun pada contoh kali ini saya akan menggunakan button ya.

Buat Module lalu ketikkan:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long

Private Type POINTAPI
X As Long
Y As Long
End Type

Public Function MouseHover(Ctl As Control) As Boolean
Dim X As Single, Y As Single
Dim xyCursor As POINTAPI

SetCapture Ctl.hwnd
GetCursorPos xyCursor
ScreenToClient Ctl.hwnd, xyCursor

X = xyCursor.X * Screen.TwipsPerPixelX
Y = xyCursor.Y * Screen.TwipsPerPixelY

If X < 0 Or Y < 0 Or X > Ctl.Width Or Y > Ctl.Height Then
ReleaseCapture
MouseHover = False
Else
MouseHover = True
End If
End Function

Sebagai contoh penggunaan pada button, buat sebuah CommandButton (Style=Graphical),
lalu pada bagian 'Command1_MouseMove' ketikkan :
If MouseHover(Command1) Then
Command1.BackColor = vbBlue
Else
Command1.BackColor = vbButtonFace
End If


DOWNLOAD PROJECT

0 komentar:

Posting Komentar

Pages

Diberdayakan oleh Blogger.

Followers

Tags

Labels