Pencil tool problem

05-30-2006, 10:08 PM
I am trying to make a pencil tool that draw where the mouse is when it is held down. It draws, but not where the pointer is. In fact, the further down and right I go, the furth the pointer is away from the line being draw. If I move the posiotn of the window the picturebox is in, to the upper left, the values get closer together, but still move apart as I go to the lower right. I can't figure out what the deal is. Can someone explain this?

if flag_draw then
dim GFX as Graphics = Graphics.FromImage(PictureBox1.Image)
GFX.DrawEllipse(MyPen, MousePosition.X, MousePosition.Y, 1, 1)
end if

05-31-2006, 03:42 AM
Sounds like the MousePosition value is in screen co-ordinates where (0,0) is the top left pixel of the screen. You can convert to local co-odinates where (0,0) is the topLeft of PictureBox1 with

Dim localPoint as point = PictureBox1.PointToClient(MousePoint)


Private Sub pb_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb.MouseMove
' the location in screen co-ordinates (0,0) is upper left of screem:
Debug.WriteLine("Screen: " & Windows.Forms.Cursor.Position.ToString)
' the location in local co-ordinates (0,0) is upper left of picturebox@
Debug.WriteLine("Local: " & pb.PointToClient(Windows.Forms.Cursor.Position).ToString)
' 2005: event args has a Location property that is already local:
Debug.WriteLine("event args: " & e.Location.ToString)
' 2003: there is no Location property, but you can use e.X and e.Y to make a new point

End Sub

05-31-2006, 09:35 AM
I am having trouble for some reason. This code works great:

dim GFX as Graphics = PictureBox1.CreateGraphics
GFX.DrawEllipse(MyPen, e.X, e.Y, 1, 1)

The only problm, is that I need to save the graphics on the image, so I use this:

dim GFX as graphics = graphics.fromimage(picturebox1.image)
GFX.DrawEllipse(MyPen, e.X, e.Y, 1, 1)


This does work, but again, the area the drawing occurs is not where the mouse is. I can figure it out.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum