迅速掌握VB.NET操作GDI图形
创始人
2024-06-20 08:00:21
0

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图形的各种操作技巧就为大家介绍到这里。

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...