Results 1 to 5 of 5

Thread: Cursor Starting position

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    10

    Cursor Starting position

    How can i make the mouse/cursor start at a specific part of the screen when i run an application? for ex: i want to make the cursor's position start on a button, so all the user has to do is click.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Cursor Starting position

    Assuming the button is called Button1 , you could use this code:
    Code:
    Button1.Select
    Another way is to open the form designer and alter the tab order of the controls, so that the control you want selected first has the lowest tab index.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Cursor Starting position

    If you set Focus to that Button then the user can just hit Enter to click it, regardless of the position of the mouse pointer. That's what si is talking about. If you really want to move the cursor then you would do something like this:
    vb.net Code:
    1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    2.     Cursor.Position = PointToScreen(New Point(Button1.Left + Button1.Width \ 2,
    3.                                               Button1.Top + Button1.Height \ 2))
    4. End Sub
    That assumes that the Button is added directly to the form. If it is added to a Panel or other container, you would need to call PointToScreen on that container rather than the form.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Cursor Starting position

    It's also worth noting that you can assign a Button to the AcceptButton property of a form and then hitting Enter will click that Button even if it doesn't have focus, as long as the control that does have focus doesn't consume the keystroke, e.g. a multiline TextBox. You can do the same with the CancelButton property and the Escape key.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Cursor Starting position

    Ah yes, I managed to overlook the word mouse, so my post may not be what is wanted... but it may still be a good idea to do it as well as the mouse.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width