gpt4 book ai didi

.net - 使用鼠标 vb.net 在图片框图像上绘制

转载 作者:行者123 更新时间:2023-12-02 22:23:31 25 4
gpt4 key购买 nike

如何在 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

关于.net - 使用鼠标 vb.net 在图片框图像上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13327311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com