#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    10
    Rep Power
    0

    Changing mouse position programmatically


    Hello everyone. I would like your assistance in learning how to do the following two things in .net:

    1. How do I alter the mouse position programmatically?

    2. How do I send an event (ie. mouse click event) to a specific control?

    Thanks a bunch,

    Tony
  2. #2
  3. I <3 ASCII
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2003
    Posts
    2,399
    Rep Power
    1232
    Originally Posted by Tony Lintunen
    Hello everyone. I would like your assistance in learning how to do the following two things in .net:

    1. How do I alter the mouse position programmatically?

    2. How do I send an event (ie. mouse click event) to a specific control?

    Thanks a bunch,

    Tony
    What would be the need to alter the mouse's position? Don't you think you'd be a bit miffed if someone didn't let you move your mouse where you wanted to?

    Why would it need to be a mouse click event, you could just move mouse click code to another part of code, such as an onload method?

    -MBirchmeier
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    10
    Rep Power
    0
    Originally Posted by MBirchmeier
    What would be the need to alter the mouse's position? Don't you think you'd be a bit miffed if someone didn't let you move your mouse where you wanted to?

    Why would it need to be a mouse click event, you could just move mouse click code to another part of code, such as an onload method?

    -MBirchmeier
    I want a way to automatically resize a datagrid's columns to the correct width. I'm not particularly fond of the method where you iterate through all the rows and set the width according to the widest row.

    I want to simulate a datagrid column click, which resizes the column appropriately. I want to do this by programmatically moving the mouse to the column's right edge, and sending a column click message to the datagrid.

    Is there a .net equivalent of the win32 api sendmessage function?

    Thanks,

    Tony
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Location
    England
    Posts
    11
    Rep Power
    0
    You could always use this:

    Code:
    Public Declare Function SetCursorPos Lib "user32" (ByVal X As Integer, ByVal Y As Integer) As Integer
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            SetCursorPos(200, 200)
        End Sub
    That will set your mouse to co-ordinates 200x200 upon clicking a command button.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    1
    Rep Power
    0
    Ah nice, thx. I needed this too
    Do you also know how to click the left mouse button after you moved the mouse?
    Thanks in advance

    Mystret

IMN logo majestic logo threadwatch logo seochat tools logo