正文

Demonstrate the Graphics object's drawin2006-06-19 19:50:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/iamben250/16012.html

分享到:

This program demonstrates the Graphics object's drawing methods: DrawLine, DrawLines, DrawPath, DrawEllipse, DrawPie, DrawRectangle, DrawRectangles, DrawArc, DrawPolygon, DrawString, DrawBezier, DrawBeziers, DrawClosedCurve, DrawCurve, and DrawImage. 
Imports System.Drawing.Drawing2D
...
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    ' Draw a line.
    e.Graphics.DrawLine(Pens.Black, 10, 10, 30, 20)

    ' Draw a series of connected lines.
    Dim pts() As Point = { _
        New Point(10, 20), _
        New Point(30, 30), _
        New Point(50, 10), _
        New Point(30, 10), _
        New Point(50, 30) _
    }
    e.Graphics.DrawLines(Pens.Blue, pts)

    ' Draw a path.
    ' Make the path.
    Dim graphics_path As New GraphicsPath
    graphics_path.AddLine(10, 40, 60, 40)
    graphics_path.AddEllipse(60, 30, 30, 20)
    e.Graphics.DrawPath(Pens.Red, graphics_path)

    ' Draw an ellipse and a pie slice on it.
    Dim rect As New Rectangle(10, 70, 40, 30)
    e.Graphics.DrawEllipse(Pens.White, rect)
    e.Graphics.DrawPie(Pens.Green, rect, 10, 45)

    ' Draw an ellipse and an arc on it.
    rect = New Rectangle(60, 70, 40, 30)
    e.Graphics.DrawEllipse(Pens.White, rect)
    e.Graphics.DrawArc(Pens.Green, rect, 10, 45)

    ' Draw a polygon.
    pts = New Point() { _
        New Point(10, 100), _
        New Point(80, 140), _
        New Point(80, 90), _
        New Point(10, 130) _
    }
    e.Graphics.DrawPolygon(Pens.Yellow, pts)

    ' Draw a rectangle.
    rect = New Rectangle(10, 150, 50, 20)
    e.Graphics.DrawRectangle(Pens.Brown, rect)

    ' Draw some rectangles.
    Dim rects() As Rectangle = { _
        New Rectangle(10, 190, 20, 30), _
        New Rectangle(20, 200, 40, 10), _
        New Rectangle(40, 180, 10, 50) _
    }
    e.Graphics.DrawRectangles(Pens.Aquamarine, rects)

    ' Draw some text.
    e.Graphics.DrawString("Hello!", _
        Me.Font, Brushes.Chocolate, 10, 250)

    ' Draw a Bezier curve.
    Dim ptfs() As PointF = { _
        New PointF(150, 25), _
        New PointF(185, 10), _
        New PointF(200, 50), _
        New PointF(160, 30) _
    }
    e.Graphics.DrawLines(Pens.LightGray, ptfs)
    For Each ptf As PointF In ptfs
        rect = New Rectangle(CInt(ptf.X - 2), CInt(ptf.Y - _
            2), 4, 4)
        e.Graphics.DrawRectangle(Pens.LightGray, rect)
    Next ptf
    e.Graphics.DrawBezier(Pens.Black, _
        ptfs(0), ptfs(1), ptfs(2), ptfs(3))

    ' Draw a series of connected Bezier curves.
    ptfs = New PointF() { _
        New PointF(150, 75), _
        New PointF(185, 60), _
        New PointF(200, 100), _
        New PointF(160, 80), _
        New PointF(160, 120), _
        New PointF(200, 140), _
        New PointF(220, 90) _
    }
    e.Graphics.DrawLines(Pens.LightGray, ptfs)
    For Each ptf As PointF In ptfs
        rect = New Rectangle(CInt(ptf.X - 2), CInt(ptf.Y - _
            2), 4, 4)
        e.Graphics.DrawRectangle(Pens.LightGray, rect)
    Next ptf
    e.Graphics.DrawBeziers(Pens.Orange, ptfs)

    ' Draw a closed curve.
    pts = New Point() { _
        New Point(150, 150), _
        New Point(200, 200), _
        New Point(180, 150), _
        New Point(130, 200) _
    }
    e.Graphics.DrawClosedCurve(Pens.BlueViolet, pts)

    ' Draw a curve (open).
    pts = New Point() { _
        New Point(150, 210), _
        New Point(200, 260), _
        New Point(180, 210), _
        New Point(130, 260) _
    }
    e.Graphics.DrawCurve(Pens.CornflowerBlue, pts)

    ' Draw an ellipse.
    rect = New Rectangle(230, 10, 50, 30)
    e.Graphics.DrawEllipse(Pens.DarkMagenta, rect)

    ' Draw an image.
    e.Graphics.DrawImage(picHidden.Image, 230, 50)
    e.Graphics.DrawImage(picHidden.Image, 250, 50, 32, 32)
    Dim dst_rect As New Rectangle(290, 50, 20, 20)
    Dim src_rect As New Rectangle(4, 4, 8, 8)
    e.Graphics.DrawImage(picHidden.Image, dst_rect, _
        src_rect, GraphicsUnit.Pixel)
End Sub

阅读(2379) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册