VB.net如何在图片picturebox上画直线,我这个代码任何线都画不出来;
PublicSubForm1_Load()HandlesMyBase.Load,PictureBox1.PaintDimgAsGraphics=PictureBox1.C...
Public Sub Form1_Load() Handles MyBase.Load, PictureBox1.Paint
Dim g As Graphics = PictureBox1.CreateGraphics()
g.DrawLine(Pens.Blue, 0, 150, 400, 150)
g.DrawLine(Pens.Blue, 200, 0, 200, 300)
End Sub
而当我把Dim g As Graphics = PictureBox1.CreateGraphics()改为Dim g As Graphics = Me.CreateGraphics()他就能在form窗体上画出来线
我最终的目的是想写一个在picturebox上绘制曲线,而且又可以在其他函数里调用该绘制函数的VB.net代码。求大神完整例程 展开
Dim g As Graphics = PictureBox1.CreateGraphics()
g.DrawLine(Pens.Blue, 0, 150, 400, 150)
g.DrawLine(Pens.Blue, 200, 0, 200, 300)
End Sub
而当我把Dim g As Graphics = PictureBox1.CreateGraphics()改为Dim g As Graphics = Me.CreateGraphics()他就能在form窗体上画出来线
我最终的目的是想写一个在picturebox上绘制曲线,而且又可以在其他函数里调用该绘制函数的VB.net代码。求大神完整例程 展开
展开全部
Dim g As Graphics = e.Graphics
更多追问追答
追问
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawCurve(Pens.Red, Points)
这样定义函数是可以的 ,但是这样怎么在其他sub里面调用?我不会,于是我就写了上面没有参数的函数
追答
其他sub里你可以用graphics g做形参,然后用e.Graphics做实参。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询