如何用VB2012写一个画线程序
展开全部
在窗体上添加一个PictureBox1控件,两个按钮控件:
代码如下:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'绘制图形的三步曲
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
MyGraphics.FillEllipse(MyBrush, 200, 200, 100, 100) '绘制一个实心圆,该圆在:直线x=200,y=200,x=200+100,y=200+100所划的矩形区域内
MyGraphics.DrawEllipse(MyPen, 200, 200, 100, 100) '绘制一个空心圆,该圆在:直线x=200,y=200,x=200+100,y=200+100所划的矩形区域内
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black, 3)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
Dim MyPoints() As Point = {New Point(20, 50), New Point(200, 30), New Point(250, 60)}
MyGraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
'MyGraphics.DrawClosedCurve(MyPen, MyPoints) '绘制光滑的封闭曲线
'MyGraphics.DrawCurve(MyPen, MyPoints) '绘制光滑的曲线
'用直线连接连点,绘制折线
Dim i As Integer
For i = 0 To 1
MyGraphics.DrawLine(MyPen, MyPoints(i), MyPoints(i + 1))
Next
End Sub
End Class
代码如下:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'绘制图形的三步曲
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
MyGraphics.FillEllipse(MyBrush, 200, 200, 100, 100) '绘制一个实心圆,该圆在:直线x=200,y=200,x=200+100,y=200+100所划的矩形区域内
MyGraphics.DrawEllipse(MyPen, 200, 200, 100, 100) '绘制一个空心圆,该圆在:直线x=200,y=200,x=200+100,y=200+100所划的矩形区域内
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black, 3)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
Dim MyPoints() As Point = {New Point(20, 50), New Point(200, 30), New Point(250, 60)}
MyGraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
'MyGraphics.DrawClosedCurve(MyPen, MyPoints) '绘制光滑的封闭曲线
'MyGraphics.DrawCurve(MyPen, MyPoints) '绘制光滑的曲线
'用直线连接连点,绘制折线
Dim i As Integer
For i = 0 To 1
MyGraphics.DrawLine(MyPen, MyPoints(i), MyPoints(i + 1))
Next
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询