Hi, is it possible so that when my VB form opens it mouseup and mousedown are automatically done without the user using the mouse? I need the click to be in the top left of the form if it's possible...
Thanks
Printable View
Hi, is it possible so that when my VB form opens it mouseup and mousedown are automatically done without the user using the mouse? I need the click to be in the top left of the form if it's possible...
Thanks
Are you clicking on a certain control? You can call a click event thru code, or use an API to click anywhere on the screen.
What are you trying to do in your app? Invoke the system menu in the control box?
You can drop down the system menu using some APIs if that what your trying to do.
Im trying to click an image in the top left of the screen. I don't know what would be a good phrase or keywords to search for some code though.
Cheers
Is this in your app or another program?
You can use the SetCursorPos API to move the mouse to the screen coordinates you desire.
SetCursorPos
How would i find the required position of the top left of the form on load..?
Your form? Form1.Left & Form1.Top ???
If you need another programs positioning then you need to use FindWindow API.
What i mean is this:
SetCursorPos (frmMain.Top), (frmMain.Left)
How do i find the X,Y position of frmMain.Left and frmMain.Top on form_load?
Thanks so far :) Im getting there
That will give you the .top and .left coordinates. Try it!
Well SetCursorPos requires the X and Y coordinates to be in pixels and the Top and Left properties of a Form will always return them in Twips so you need to divide them with Screen.TwipsPerPixelX and Screen.TwipsPerPixelX.
But if this is your programs form why not just call the Image1_Click event procedure (if Image1 is the name of your image)?
Whatever i do the cursor starts at the top left of the monitor not the form..?
If your image is called Image1, just use this:
VB Code:
Option Explicit Private Sub Form_Load() Image1_Click End Sub Private Sub Image1_Click() Beep End Sub
and your image will be clicked.
if your app = true then
use Image1_Click(),
else
use the api
endif
I'm not trying to do image_click... I want VB to click on the image for me, so that MouseDown and MouseUp are used...The clicking isn't the problem, just starting the mouse in the top left hand side of the form.
Thanks
Mouse Down and Mouse up is the same thing as a click, and that's what will execute if you execute mouse down and mouse up. You can click on the form, if that's what you want using the Form_Click event.
What exactly are you trying to do? Perhaps I am misubderstanding...
I'm trying to take a screenie of an object. If i click the image whilst the programme is running it works, if i use image1_click it doesn't.
VB Code:
Public Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.MousePointer = 99 Me.MouseIcon = Picture1.Picture Picture1.Visible = False End Sub Public Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim mousexy As PointAPI GetCursorPos mousexy SelWnd = WindowFromPoint(mousexy.X, mousexy.Y) Me.MousePointer = 0 Picture1.Visible = True End Sub Private Sub form_load() Picture1_Click End Sub
You could use SPY++ to get a handle to the object that you want to click.
Is it your own app? Is it always the same app? Same object?
It's my own form, my own app. The picture box is always there, same place..
try this, just adjust to get exactly where you want
SetCursorPos Me.Left / Screen.TwipsPerPixelX + 10, Me.top / Screen.TwipsPerPixelY + 100
pete
If it is a Picture Box and not an Image control then use this code:VB Code:
Private Declare Function SetCursorPos Lib "user32.dll" ( _ ByVal x As Long, _ ByVal y As Long) As Long Private Declare Function GetWindowRect Lib "user32.dll" ( _ ByVal hwnd As Long, _ ByRef lpRect As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Sub Form_Load() Dim r As RECT 'Show the Form so the picture box is visible Me.Show Call GetWindowRect(Picture1.hWnd, r) Call SetCursorPos(r.Left, r.Top) End Sub
Sorted! Thanks everyone :D :thumb: