2009年11月2日

VB.Net画图的实例(2009-08-11 16:42:59)

 Public Class DrawsForm

    Dim graph As Graphics = Me.CreateGraphics

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ''绘制直线

        Dim mypen1 As Pen = New Pen(Color.Blue, 5)

        Dim mypen2 As Pen = New Pen(Color.Red, 5)

        mypen1.LineJoin = Drawing2D.LineJoin.Round ''2条线连接类型

        mypen2.LineJoin = Drawing2D.LineJoin.Round

        Dim Point1 As New Point(50, 50)

        Dim Point2 As New Point(60, 100)

        mypen1.DashStyle = Drawing2D.DashStyle.Dot

        mypen2.DashStyle = Drawing2D.DashStyle.Dash

        graph.DrawLine(mypen1, Point1, Point2)

        graph.DrawLine(mypen2, 50, 50, 100, 100)

        mypen1.Dispose()

        mypen2.Dispose()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        graph.Clear(Me.BackColor) '清除,就是用背景色填充

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        ''绘制圆

        Dim mypen1 As Pen = New Pen(Color.Blue, 5)

        Dim mypen2 As Pen = New Pen(Color.Red, 5)

        Dim rectangle1 As Rectangle = New Rectangle(50, 50, 100, 100)

        'graph.DrawEllipse(mypen1, 50, 50, 100, 100) ' 绘制圆

        graph.DrawEllipse(mypen1, rectangle1) ' 绘制圆

        graph.DrawEllipse(mypen2, 50, 50, 150, 200) '绘制椭圆

        mypen1.Dispose()

        mypen2.Dispose()

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        ''绘制矩形

        Dim mypen1 As Pen = New Pen(Color.Blue, 5)

        Dim mypen2 As Pen = New Pen(Color.Red, 5)

        ' Dim rectangle1 As Rectangle = New Rectangle(50, 50, 100, 100)

        'Dim rectangle2 As Rectangle = New Rectangle(10, 10, 90, 150)

        graph.DrawRectangle(mypen1, 50, 50, 100, 100)

        graph.DrawRectangle(mypen2, 10, 10, 90, 150)

        'graph.DrawRectangle(mypen1, rectangle1)

        'graph.DrawRectangle(mypen2, rectangle2)

        mypen1.Dispose()

        mypen2.Dispose()

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        ''绘制曲线

        Dim mypen As Pen = New Pen(Color.Blue, 5)

        Dim points1(20) As Point

        For i As Integer = 1 To 20 '初始化曲线上点数组

            points1(i).X = i ^ 3

            points1(i).Y = i * 10

        Next

        graph.DrawCurve(mypen, points1)

        mypen.Dispose()

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

        ''绘制折线

        Dim mypen As Pen = New Pen(Color.Blue, 5)

        Dim points1(3) As Point

        points1(0).X = 0

        points1(0).Y = 0

        points1(1).X = 100

        points1(1).Y = 100

        points1(2).X = 150

        points1(2).Y = 50

        points1(3).X = 300

        points1(3).Y = 300

        graph.DrawLines(mypen, points1)

        mypen.Dispose()

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

        ''绘制文本

        Dim myfont As Font = New Font("黑体", 12)

        Dim mypen As Pen = New Pen(Color.Red, 5)

        Dim forma As StringFormat = New StringFormat(StringFormatFlags.DirectionVertical)

        graph.DrawString("绘制文本", myfont, mypen.Brush, 100, 100, forma)

    End Sub

End Class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值