4 Replies - 19936 Views - Last Post: 26 March 2013 - 11:18 AM Rate Topic: -----

#1 GPerk2   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-March 13

Detecting mouse click on desktop screen, not on the Form

Posted 24 March 2013 - 07:55 PM

How do I detect the position of a mouse click on the DESKTOP SCREEN from a running vb program?

This question has been misunderstood several times, so I will rephrase it:

My VB.NET program is running and the Form is on the screen.
When I move the cursor OFF the form and ONTO the Screen and click, then I want to capture the X,Y position.
Is This A Good Question/Topic? 0
  • +

Replies To: Detecting mouse click on desktop screen, not on the Form

#2 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1538
  • View blog
  • Posts: 3,869
  • Joined: 01-February 13

Re: Detecting mouse click on desktop screen, not on the Form

Posted 24 March 2013 - 08:28 PM

Hello GPerk2,
Here is a quick way to get the position. I used 1 Timer and a textbox on the form and wherever you click the mouse on the screen the X and Y position will show in the textbox. You can stop the timer in the tick event if you only want to capture the position once.
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
        Timer1.Interval = 100
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If MouseButtons = Windows.Forms.MouseButtons.Left Then
            TextBox1.Text = "X=" & MousePosition.X.ToString & "  Y=" & MousePosition.Y.ToString
        End If
    End Sub
End Class


:bigsmile:
Was This Post Helpful? 3
  • +
  • -

#3 C.Andrews   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: Detecting mouse click on desktop screen, not on the Form

Posted 25 March 2013 - 08:38 AM

View PostIronRazer, on 25 March 2013 - 03:28 AM, said:

Hello GPerk2,
Here is a quick way to get the position. I used 1 Timer and a textbox on the form and wherever you click the mouse on the screen the X and Y position will show in the textbox. You can stop the timer in the tick event if you only want to capture the position once.
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
        Timer1.Interval = 100
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If MouseButtons = Windows.Forms.MouseButtons.Left Then
            TextBox1.Text = "X=" & MousePosition.X.ToString & "  Y=" & MousePosition.Y.ToString
        End If
    End Sub
End Class


:bigsmile:/>


Ha, cool trick!
Was This Post Helpful? 1
  • +
  • -

#4 GPerk2   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-March 13

Re: Detecting mouse click on desktop screen, not on the Form

Posted 26 March 2013 - 10:54 AM

C.ANDREWS

Thanks a bunch. I tried this and it worked the first time!

GPerk
Was This Post Helpful? 0
  • +
  • -

#5 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1538
  • View blog
  • Posts: 3,869
  • Joined: 01-February 13

Re: Detecting mouse click on desktop screen, not on the Form

Posted 26 March 2013 - 11:18 AM

View PostGPerk2, on 26 March 2013 - 12:54 PM, said:

C.ANDREWS

Thanks a bunch. I tried this and it worked the first time!

GPerk

Your welcome. Glad it helped. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1