1
如何在vb.net上使用鼠標在線上繪製圖片框圖片?使用鼠標在圖片框圖像上繪製vb.net
如何在vb.net上使用鼠標在線上繪製圖片框圖片?使用鼠標在圖片框圖像上繪製vb.net
轉換a similar question從C#到VB.NET,用線 - 測試工作:
Private _Previous As System.Nullable(Of Point) = Nothing
Private Sub pictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
_Previous = e.Location
pictureBox1_MouseMove(sender, e)
End Sub
Private Sub pictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If _Previous IsNot Nothing Then
If PictureBox1.Image Is Nothing Then
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Using g As Graphics = Graphics.FromImage(bmp)
g.Clear(Color.White)
End Using
PictureBox1.Image = bmp
End If
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.DrawLine(Pens.Black, _Previous.Value, e.Location)
End Using
PictureBox1.Invalidate()
_Previous = e.Location
End If
End Sub
Private Sub pictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
_Previous = Nothing
End Sub
我已經修改了你的代碼放置在鼠標點擊一個「點」,它可以移動(覆蓋)
我需要的是用於多個「點」,比如說四個。
用戶從列表中選擇一個標記,並將它放置在圖片框上,然後他們選擇另一個並放置在不同的位置,但它會覆蓋上一個標記。
Marker = Lst_Markers.SelectedIndex + 1
If _Previous IsNot Nothing Then
For i As Integer = 0 To Marker
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = bmp
Next
Select Case Marker
Case 1
'PictureBox1.Image = bmp1
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Red, e.X, e.Y, 10, 10)
End Using
Case 2
'PictureBox1.Image = bmp2
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Yellow, e.X, e.Y, 10, 10)
End Using
Case 3
'PictureBox1.Image = bmp3
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Green, e.X, e.Y, 10, 10)
End Using
Case 4
'PictureBox1.Image = bmp4
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Blue, e.X, e.Y, 10, 10)
End Using
Case Else
MsgBox("Select a marker")
End Select
PictureBox1.Invalidate()
_Previous = e.Location
End If