그리는 몇 가지 선에 이미지와 마우스 이동

0

질문

나는 몇 가지 선에 이미지 마우스를 사용하여 이동 vb.net. 내 문제는 시작할 때 내 그림은 다음 줄,이전 선라! 누구든지 나를 도울 수 있습니까? 나의 코드의 사진과 함께 프로젝트 실행

Dim st, en As New Point
Dim p As Pen
Private mouseButtonPressed As Boolean = False

Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
    p = New Pen(Color.Black, 2)
    Dim g As Graphics = e.Graphics
    g.DrawLine(p, st, en)
End Sub

Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
    mouseButtonPressed = False
End Sub

Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
    If mouseButtonPressed Then
        PictureBox1.Invalidate()
        en = e.Location
    End If
End Sub

Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
    If e.Button = MouseButtons.Left Then
        st = New Point(e.X, e.Y)
        mouseButtonPressed = True
    End If
End Sub

GIF of my run project

drawing vb.net
2021-11-23 06:07:57
1

최고의 응답

0

저장할 수 있습니다 라인 목록에서 그들이 완료되면 다음을 그리는 모든 이전인 경우는 그림 라이브 하나

Private st, en As New Point
Private mouseButtonPressed As Boolean = False

Private lines As New List(Of (st As Point, en As Point))

Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
    Dim p = New Pen(Color.Black, 2)
    Dim g As Graphics = e.Graphics
    g.DrawLine(p, st, en)
    For Each line In lines
        g.DrawLine(p, line.st, line.en)
    Next
End Sub

Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
    mouseButtonPressed = False
    lines.Add((st, en))
End Sub

Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
    If mouseButtonPressed Then
        PictureBox1.Invalidate()
        en = e.Location
    End If
End Sub

Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
    If e.Button = MouseButtons.Left Then
        st = New Point(e.X, e.Y)
        mouseButtonPressed = True
    End If
End Sub

목록 보유 Tuple(of Point, Point)

2021-11-23 15:48:51

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................