Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set cursor position

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
GR
How can I set cursor position with Visual Basic? Can somebody give me an example code?
 
Is that a database cursor, a screen cursor or a Bookmark? A bit more detail will help


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Use the SetCursorPos API.
___

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

...

SetCursorPos x, y ' Where x and y are in screen coordinates
 
Try this:
Me.CurrentX = 3000
Me.CurrentY = 1000
Me.Print "HELLO WORLD"

The Me keyword specifies the form that the code runs in.


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
What is a cursor position? The one blinking in the text box?

Or you mean the focus?

TO set the focus, use Control.SetFocus method
To set the cursor in a textbox at the particualr letter, use

Text1.SelStart = 1

You dont have to make the 1 hardcoded, it can come from a variable also.

Sunil
 
Apart from the API I don't think the others will yield the mouse pointer co-ords which is how I read the question. Without looking at API's I came to the conclsion that it was not obvious. I tried a few properties but gave-up and found a different way of doing things like click events,

Form_OnMouseDown(button, X,Y) or something similar though if the click is in an object it fails. Look at OnMouse Over events - and fill the form with a picture box if necessary and use that as the carryer of the co-ords.

though there was a drag and drop thing I looked at - would this help? Click to set, drag an icon and click again to drop. I saw the code in the "samples" via a trial and error search in Help.

If see anything more useful when I get back to my machine I will post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top