get mouse location

Syntax

Member
Joined
Nov 6, 2003
Messages
10
I need to get the mouse possision into 2 integers
is there an easy way to get this code done?

ive been searching the net for like 8 hours and only found from VB 6
but that metod is not supported in VB .NET

Hope someone can help me with this probobly simple problem.
 
The mouse_move, mouse_up and mouse_down all contain the x, y co-ordinates as part of the arguments.
e.X, e.Y respectively.

Or are you looking for the position in some other way?
 
im making a drawing program so i need
to draw a line with mousedown cordinates to mouseup cordinates.
 
Just handle the mouse move events and store the position from the X and Y properties of MouseEventArgs. Get the stored values in your Paint event and do the drawing there.

Simple.
 
sorry if i have no clue on what your talking about..
im going a visual basic course at school and im trying to learn graphics while they others still do if then else


the code i got so far is to draw a line.

Code:
 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
       


        Dim g As Graphics = e.Graphics
        Dim pn As New Pen(Color.Black, 3)
        Dim xval As Integer
        Dim yval As Integer
        Dim pt1 As Point = New Point(30, 30)
        Dim pt2 As Point = New Point(110, 100)

       
        g.DrawLine(pn, pt1, pt2)
    End Sub
 
here, I did my own GDI+ Drag-and-drop system for a card game:

Code:
    Dim LastMousePos as New Point(0, 0)
    Dim CurrMousePos as New Point(0, 0)

    Private Sub pbx_MouseDown(Byval sender as object, byval e as MouseEventArgs) Handles pbx.MouseDown
        LastMousePos.X = CurrMousePos.X
        LastMousePos.Y = CurrMousePos.Y
        CurrMousePos.X = e.X
        CurrMousePos.Y = e.Y
    End Sub

 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = e.Graphics
        Dim pn As New Pen(Color.Black, 3)
       
        g.DrawLine(pn, LastMousePos, CurrMousePos)
    End Sub

Its late here, I hope this works.
 
You can always use Cursor.Position.X and Cursor.Position.Y if you dont feel like using events.
 
as usual i dont know how to do it..
i need
1 function to draw the line
and i need mousedown to call that function but i have no idea on how to code it..
if anyone can give me the code or would like to help me realtime throu icq or anything please post here.
 
Since youre going to a VB.NET class, why not ask your teacher? Its easier to show someone how to do something than it is to explain it over the internet.
 
well the teacher wont show me when im home..
also i just need the to know how to call the function..
but i just dont know how to
its always something thats not working.
 
Originally posted by Darc
here, I did my own GDI+ Drag-and-drop system for a card game:

Code:
    Dim LastMousePos as New Point(0, 0)
    Dim CurrMousePos as New Point(0, 0)

    Private Sub pbx_MouseDown(Byval sender as object, byval e as MouseEventArgs) Handles pbx.MouseDown
        LastMousePos.X = CurrMousePos.X
        LastMousePos.Y = CurrMousePos.Y
        CurrMousePos.X = e.X
        CurrMousePos.Y = e.Y
    End Sub

 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = e.Graphics
        Dim pn As New Pen(Color.Black, 3)
       
        g.DrawLine(pn, LastMousePos, CurrMousePos)
    End Sub

Its late here, I hope this works.

Nope didnt work i must call the draw line function from within the mousedown event.

but i wouldnt know hopw to do that.
 
Back
Top