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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse On Startup

Status
Not open for further replies.

Dewey

Programmer
Jan 25, 2000
21
US
When I open a form for the first time, I want the Mouse to be at a certain location, so that the ToolTipText becomes visible immediately.&nbsp;&nbsp;I know this must be simple, but I have never needed to do this before.....I have looked in many VB books, and can't get an answer....Any help would be appreciated, and then maybe I can get up to the next hurdle.&nbsp;&nbsp;This Visual Basic progamming is more fun than &quot;cross word puzzles.....<br><br>thanks, in advance......Dewey <p>Dewey Davis<br><a href=mailto:ddavis@dfn.com>ddavis@dfn.com</a><br><a href= > </a><br>
 
Dewey -<br><br>Look at the SetCursorPos() API.&nbsp;&nbsp;You pass it two longs which are the X screen position and the Y screen position for the mouse pointer.&nbsp;&nbsp;It returns a BOOL (long), where a non-zero indicates success.&nbsp;&nbsp;The APITextViewer that ships with Visual Basic can spit out the declare statement for you -- you just have to paste it into your code.&nbsp;&nbsp;Here's it anyway:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Private Declare Function SetCursorPos Lib &quot;user32&quot; Alias &quot;SetCursorPos&quot; (ByVal x As Long, ByVal y As Long) As Long<br><br>Note that you have to first set your form's scalemode property to pixels, then add the scaletop and the scaleleft values to the X & Y values to the SetCursorPos call to make sure that you're starting off on <b>your</b> form, and not over some other program's window.<br><br>Moving the mouse pointer for the user could be considered annoying.&nbsp;&nbsp;You might want to have an option for &quot;Show help tip at startup&quot; to enable/disable this feature. Don't forget that the tooltip won't show up until the delay has expired.<br><br>Chip H.<br>
 
'Add a module to your project (In the menu choose Project -&gt; Add Module, Then click Open)<br>'Add 2 CommandButtons to your form. Run the program and move between buttons <br>'with TAB key. We show this example on CommandButtons, but You can do the same <br>'thing with other controls.<br>'Insert the following code to your module:<br><br>Declare Sub SetCursorPos Lib &quot;User32&quot; (ByVal X As Integer, ByVal Y As Integer)<br><br>'Insert the following code to your form:<br><br>Private Sub Command1_GotFocus()<br>'Replace All 'Command1' With the name of the control you want to move the cursor to him. <br>X% = (Form1.Left + Command1.Left + Command1.Width / 2 + 60) / Screen.TwipsPerPixelX<br>Y% = (Form1.Top + Command1.Top + Command1.Height / 2 + 360) / Screen.TwipsPerPixelY<br>SetCursorPos X%, Y%<br>End Sub<br><br> <p>Eric De Decker<br><a href=mailto:vbg.be@vbgroup.nl>vbg.be@vbgroup.nl</a><br><a href= Visual Basic Forum</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top