用VB.NET绘制GDI图形

 
  1. 用VB.NET绘制GDI图形 
  2.   下面的例子通过重载Form1窗体的OnPaint()方法绘制GDI图形
  3. Protected Overrides Sub onpaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  4. 注释:/绘制任意直线
  5. Dim g As Graphics = e.Graphics
  6. Dim mypen As Pen = New Pen(Color.Red, 2)
  7. g.DrawLine(mypen, 100, 100, 10, 10)
  8. 注释:/绘制矩形(任意直线构成的封闭图形)
  9. Dim point1 As PointF = New PointF(100F, 100F)
  10. Dim point2 As PointF = New PointF(200F, 100F)
  11. Dim point3 As PointF = New PointF(200F, 200F)
  12. Dim point4 As PointF = New PointF(100F, 200F)
  13. Dim curvepoints As PointF() = {point1, point2, point3, point4}
  14. g.DrawPolygon(New Pen(Color.Blue, 2), curvepoints)
  15. 注释:文本表示
  16. Dim FFamily As FontFamily = New FontFamily("Arial")
  17. Dim font As Font = New Font(FFamily, "20", FontStyle.Bold, FontStyle.Italic, GraphicsUnit.Pixel)
  18. Dim text As String = "I love you!"
  19. Dim solidbrush As SolidBrush = New SolidBrush(Color.Red)
  20. Dim pr As PointF = New PointF(100, 10)
  21. e.Graphics.DrawString(text, font, solidbrush, pr)
  22. 注释:平面绘制
  23. Dim rec As RectangleF = New RectangleF(10, 10, 200, 100)
  24. g.DrawPie(mypen, rec, 150, 150)
  25. 注释:///封闭图形,0.7应该是个圆
  26. g.DrawClosedCurve(mypen, curvepoints, 0.7, Drawing.Drawing2D.FillMode.Alternate)
  27. 注释:///大家自己试试看吧
  28. g.DrawArc(mypen, 300, 300, 200, 200, 100, 100)
  29. g.DrawCurve(mypen, curvepoints)
  30. g.DrawBezier(mypen, 50, 50, 100, 50, 100, 100, 50, 100)
  31. g.DrawBeziers(mypen, curvepoints)
  32. 注释://这可是一个圆
  33. Dim rec1 As RectangleF = New RectangleF(10, 10, 100, 100)
  34. g.DrawEllipse(mypen, rec1)
  35. 注释://这是一个椭圆
  36. Dim rec2 As RectangleF = New RectangleF(10, 10, 200, 100)
  37. g.DrawEllipse(mypen, rec2)
  38. End Sub 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值