|
-
Jan 12th, 2008, 08:58 AM
#1
Thread Starter
Frenzied Member
Toolbar and picturebox
I have toolbar,How do I move cursor to the picturebox when I pressed button in the toolbar?
-
Jan 12th, 2008, 09:08 AM
#2
Re: Toolbar and picturebox
Have a look at this link!
It seems to be a very neat way of doing what you ask Only you will put the code in the button's click event of the toolbar
-
Jan 12th, 2008, 09:12 AM
#3
Re: Toolbar and picturebox
Would this work for you?
Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Sub Command1_Click()
Dim rc As RECT
GetWindowRect Picture1.hwnd, rc
SetCursorPos rc.Left, rc.Top
End Sub
-
Jan 12th, 2008, 09:16 AM
#4
Re: Toolbar and picturebox
That code works effectively as well 
The only difference now is if you want it to go to the center (the link i posted) of the picture box) or the corner (rhino's post)
-
Jan 12th, 2008, 09:17 AM
#5
Thread Starter
Frenzied Member
Re: Toolbar and picturebox
a'a it helpful... but how to make the cursor to the center of the picturebox?
-
Jan 12th, 2008, 09:17 AM
#6
Re: Toolbar and picturebox
-
Jan 12th, 2008, 09:19 AM
#7
Thread Starter
Frenzied Member
Re: Toolbar and picturebox
Link you give to me is totally lot of code but the RhinoBull post is easier to identify
-
Jan 12th, 2008, 09:23 AM
#8
Re: Toolbar and picturebox
Code:
Private Sub cmdClick_Click()
Const NUM_MOVES = 3000
Dim pt As POINTAPI
Dim cur_x As Single
Dim cur_y As Single
Dim dest_x As Single
Dim dest_y As Single
Dim dx As Single
Dim dy As Single
Dim i As Integer
ScaleMode = vbPixels
picClicker.ScaleMode = vbPixels
GetCursorPos pt
cur_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, _
vbPixels)
cur_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, _
vbPixels)
pt.X = picClicker.ScaleWidth / 2
pt.Y = picClicker.ScaleHeight / 2
ClientToScreen picClicker.hwnd, pt
dest_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, _
vbPixels)
dest_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, _
vbPixels)
dx = (dest_x - cur_x) / NUM_MOVES
dy = (dest_y - cur_y) / NUM_MOVES
For i = 1 To NUM_MOVES - 1
cur_x = cur_x + dx
cur_y = cur_y + dy
mouse_event _
MOUSEEVENTF_ABSOLUTE + _
MOUSEEVENTF_MOVE, _
cur_x, cur_y, 0, 0
DoEvents
Next i
mouse_event _
MOUSEEVENTF_ABSOLUTE + _
MOUSEEVENTF_MOVE + _
MOUSEEVENTF_LEFTDOWN + _
MOUSEEVENTF_LEFTUP, _
dest_x, dest_y, 0, 0
End Sub
Does that look better Yea your right though his code is simpler but i am not sure if API might be faster or not.
-
Jan 12th, 2008, 09:29 AM
#9
Thread Starter
Frenzied Member
Re: Toolbar and picturebox
I got error at this line. The second line from top
Dim pt As POINTAPI
-
Jan 12th, 2008, 11:25 AM
#10
Re: Toolbar and picturebox
 Originally Posted by matrik02
a'a it helpful... but how to make the cursor to the center of the picturebox?
You just had to improvise a little.
Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Sub Command1_Click()
Dim rc As RECT
GetWindowRect Picture1.hwnd, rc
SetCursorPos rc.Left + (rc.Right - rc.Left) / 2, rc.Top + (rc.Bottom - rc.Top) / 2
End Sub
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
|