迅速掌握VB.NET操作GDI图形

开发 后端
VB.NET操作GDI图形的操作方法有很多种,运用VB.NET对这一类型的图像进行操作,可以帮助开发人员轻松的完成各种功能需求。

VB.NET编程语言在对图形的操作上可以体现出其全面和灵活性。我们可以通过VB.NET操作GDI图形的相关操作方法和实现的功能来对这一方面的知识进行一个系统的认识,了解VB.NET在操作中的简便灵活性。#t#

下面的例子通过重载Form1窗体的OnPaint()方法绘制GDI图形

  1. Protected Overrides Sub onpaint
    (ByVal e As System.Windows.
    Forms.PaintEventArgs) 

注释://///////////VB.NET操作GDI图形绘制任意直线

  1. Dim g As Graphics = 
    e.Graphics  
  2. Dim mypen As Pen = 
    New Pen(Color.Red, 2)  
  3. g.DrawLine(mypen, 
    100, 100, 10, 10) 

注释://///////////绘制矩形(任意直线构成的封闭图形)

  1. Dim point1 As PointF = 
    New PointF(100F, 100F)  
  2. Dim point2 As PointF = 
    New PointF(200F, 100F)  
  3. Dim point3 As PointF = 
    New PointF(200F, 200F)  
  4. Dim point4 As PointF = 
    New PointF(100F, 200F)  
  5. Dim curvepoints As PointF() 
    = {point1, point2,
     point3, point4}  
  6. g.DrawPolygon(New 
    Pen(Color.Blue, 2), 
    curvepoints) 

注释:////////////VB.NET操作GDI图形文本表示

  1. Dim FFamily As FontFamily = 
    New FontFamily("Arial")  
  2. Dim font As Font = New Font
    (FFamily, "20", FontStyle.
    Bold, FontStyle.Italic, 
    GraphicsUnit.Pixel)  
  3. Dim text As String =
     
    "I love you!" 
  4. Dim solidbrush As SolidBrush 
    New SolidBrush(Color.Red)  
  5. Dim pr As PointF = 
    New PointF(100, 10)  
  6. e.Graphics.DrawString
    (text, font, solidbrush, pr) 

注释:////////////VB.NET操作GDI图形平面绘制

  1. Dim rec As RectangleF = 
    New RectangleF(10, 10, 
    200, 100)  
  2. g.DrawPie(mypen, rec, 
    150, 150) 

注释:///////////封闭图形,0.7应该是个圆

  1. g.DrawClosedCurve(mypen, 
    curvepoints, 0.7, Drawing.
    Drawing2D.FillMode.Alternate) 

注释:///////////大家自己试试看吧

  1. g.DrawArc(mypen, 300, 300, 
    200, 200, 100, 100)  
  2. g.DrawCurve(mypen, curvepoints)  
  3. g.DrawBezier(mypen, 50, 50, 
    100, 50, 100, 100, 50, 100)  
  4. g.DrawBeziers(mypen, curvepoints) 

注释://////////这可是一个圆

  1. Dim rec1 As RectangleF = 
    New RectangleF(10, 10, 100, 100)  
  2. g.DrawEllipse(mypen, rec1) 

注释://////////这是一个椭圆

  1. Dim rec2 As RectangleF = 
    New RectangleF(10, 10, 200, 100)  
  2. g.DrawEllipse(mypen, rec2)  
  3. End Sub  

VB.NET操作GDI图形的各种操作技巧就为大家介绍到这里。

责任编辑:曹凯 来源: 博客园
相关推荐

2010-01-11 14:28:14

VB.NET操作Exc

2009-10-29 13:38:05

VB.NET Shar

2010-01-07 11:07:20

VB.NET读取INI

2009-10-16 10:36:35

VB.NET绘制GDI

2009-10-30 16:40:04

VB.NET Inte

2010-01-11 10:34:41

VB.NET图像操作

2010-01-08 18:10:44

VB.NET实现任务栏

2010-01-11 15:54:48

VB.NET操作缩放图

2010-01-22 18:08:18

VB.NET与GDI结

2011-05-20 16:56:11

VB.NETGDI

2009-10-29 09:06:26

VB.NET Web

2009-10-29 14:16:32

VB.NET读写文本文

2010-01-08 18:16:52

VB.NET变量

2010-01-14 13:59:01

2010-01-13 17:47:59

VB.NET拖放

2009-10-23 16:43:01

VB.NET绘制图形

2010-01-14 10:07:08

VB.NET文件名排序

2010-01-18 19:36:52

VB.NET调整控件

2009-11-10 13:43:28

VB.NET Comm

2009-10-27 14:50:25

VB.NET控件数组
点赞
收藏

51CTO技术栈公众号