Draw Straight line on picutrebox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ben3eeE
    New Member
    • Dec 2006
    • 8

    Draw Straight line on picutrebox?

    Im having trouble making a Paint.exe straight line draw.

    You know the one where you point out where to start then hold down the
    mouse button and release it to finish the drawing. My problem is that
    if i move the mouse back the line should move back with it and if i
    spin the mouse the line should spin and dont draw anything before i release
    the button.
    im using Microsoft visual stuido.net 2003


    Heres my code now:

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
    ritfält.Image = New Bitmap(ritfält. Width, ritfält.Height, System.Drawing. Imaging.PixelFo rmat.Format24bp pRgb)
    Grafik = Graphics.FromIm age(ritfält.Ima ge)
    Grafik.Clear(Co lor.White)
    End Sub

    'mouse move in the picturebox
    Private Sub ritfält_MouseMo ve(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles ritfält.MouseMo ve
    If drawing = True Then
    If Not e.Button = MouseButtons.Le ft Then Exit Sub Else
    Grafik = ritfält.CreateG raphics
    Färg = Color.FromName( CStr(PennFärg))
    Penna = New Pen(Färg, 2)
    Grafik.DrawLine (Penna, sngx, sngy, e.X, e.Y)
    sngx = e.X
    sngy = e.Y
    'force a redraw
    Me.ritfält.Refr esh()
    End If
    End Sub

    'mouse down in the picturebox
    dragging = true
    sngx = e.X
    sngy = e.Y

    'mouseup in the picturebox
    dragging = false
Working...