vb.net 画图 如何保持图形 40
PublicClasstestDimbuttonAsInteger=0PrivateSubButton1_Click(ByValsenderAsSystem.Object...
Public Class test
Dim button As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myBitMap As New Bitmap(PictureBoxTest.Width, PictureBoxTest.Height) '定义一个位图
PictureBoxTest.Image = myBitMap
Dim myGraphics As Graphics = Graphics.FromImage(myBitMap)
Dim penRed As Pen = New Pen(Color.Red, 1) '定义红色画笔
Dim penblue As Pen = New Pen(Color.Blue, 1) '定义蓝色画笔
If button = 0 Then
myGraphics.DrawLine(penRed, 0, 0, 100, 100)
button = 1
ElseIf button = 1 Then
myGraphics.DrawLine(penblue, 100, 100, 200, 200)
button = 0
End If
End Sub
End Class
代码如上,在图片控件PictureBoxTest上建立一个Graphics对象。点一下画一条直线。如何能在画本条直线的时候,保持上一条直线不会消失呢? 展开
Dim button As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myBitMap As New Bitmap(PictureBoxTest.Width, PictureBoxTest.Height) '定义一个位图
PictureBoxTest.Image = myBitMap
Dim myGraphics As Graphics = Graphics.FromImage(myBitMap)
Dim penRed As Pen = New Pen(Color.Red, 1) '定义红色画笔
Dim penblue As Pen = New Pen(Color.Blue, 1) '定义蓝色画笔
If button = 0 Then
myGraphics.DrawLine(penRed, 0, 0, 100, 100)
button = 1
ElseIf button = 1 Then
myGraphics.DrawLine(penblue, 100, 100, 200, 200)
button = 0
End If
End Sub
End Class
代码如上,在图片控件PictureBoxTest上建立一个Graphics对象。点一下画一条直线。如何能在画本条直线的时候,保持上一条直线不会消失呢? 展开
2个回答
展开全部
不用PictureBoxTest.Image属性,直接把图形绘制到PictureBoxTest上面就可以了。
Dim button As Integer = 0
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles Button1.Click
Using g As Graphics = Graphics.FromHwnd(PictureBoxTest.Handle)
Dim penRed As Pen = New Pen(Color.Red, 1) '定义红色画笔
Dim penblue As Pen = New Pen(Color.Blue, 1) '定义蓝色画笔
If button = 0 Then
g.DrawLine(penRed, 0, 0, 100, 100)
button = 1
ElseIf button = 1 Then
g.DrawLine(penblue, 100, 100, 200, 200)
button = 0
End If
End Using
End Sub
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询