您所在的位置:开发 > .NET > VB.NET > 用VB.NET绘制GDI图形

用VB.NET绘制GDI图形

2006-12-06 17:11 中国IT实验室 我要评论(0) 字号:T | T
一键收藏,随时查看,分享好友!

本文通过例子讲述如何通过重载Form1窗体的OnPaint()方法来绘制GDI图形,给出了源代码。

AD:

Protected Overrides Sub onpaint(ByVal e As System.Windows.Forms.PaintEventArgs)
注释://///////////绘制任意直线
Dim g As Graphics = e.Graphics
Dim mypen As Pen = New Pen(Color.Red, 2)
g.DrawLine(mypen, 100, 100, 10, 10)
注释://///////////绘制矩形(任意直线构成的封闭图形)
Dim point1 As PointF = New PointF(100F, 100F)
Dim point2 As PointF = New PointF(200F, 100F)
Dim point3 As PointF = New PointF(200F, 200F)
Dim point4 As PointF = New PointF(100F, 200F)
Dim curvepoints As PointF() = {point1, point2, point3, point4}
g.DrawPolygon(New Pen(Color.Blue, 2), curvepoints)
注释:////////////文本表示
Dim FFamily As FontFamily = New FontFamily("Arial")
Dim font As Font = New Font(FFamily, "20", FontStyle.Bold, FontStyle.Italic,

GraphicsUnit.Pixel)
Dim text As String = "I love you!"
Dim solidbrush As SolidBrush = New SolidBrush(Color.Red)
Dim pr As PointF = New PointF(100, 10)
e.Graphics.DrawString(text, font, solidbrush, pr)
注释:////////////平面绘制
Dim rec As RectangleF = New RectangleF(10, 10, 200, 100)
g.DrawPie(mypen, rec, 150, 150)
注释:///////////封闭图形,0.7应该是个圆
g.DrawClosedCurve(mypen, curvepoints, 0.7,

Drawing.Drawing2D.FillMode.Alternate)
注释:///////////大家自己试试看吧
g.DrawArc(mypen, 300, 300, 200, 200, 100, 100)
g.DrawCurve(mypen, curvepoints)
g.DrawBezier(mypen, 50, 50, 100, 50, 100, 100, 50, 100)
g.DrawBeziers(mypen, curvepoints)
注释://////////这可是一个圆
Dim rec1 As RectangleF = New RectangleF(10, 10, 100, 100)
g.DrawEllipse(mypen, rec1)
注释://////////这是一个椭圆
Dim rec2 As RectangleF = New RectangleF(10, 10, 200, 100)
g.DrawEllipse(mypen, rec2)
End Sub

这些是我自己试验出来的,当然了,还有好多,我只是开了一个头,大家要是发现什么好东东,别忘了通知一下:)

(责任编辑 火凤凰 sunsj@51cto.com  TEL:(010)68476636-8007)


关于.Net  VB  GDI的更多文章

网友评论TOP5

查看所有评论(

提交评论

  1. 编程排行榜:图形编程的LOGO语言
  2. 什么是响应式Web设计?

热点专题

更多>>

读书

Java EE 5 开发指南
本书是对Java EE各种技术之间互相协作的概览和补充。 本书还展示了如何编写JavaServer Page(JSP)页面或者企业级JavaBean(EJ

51CTO旗下网站

领先的IT技术网站 51CTO 领先的中文存储媒体 WatchStor 中国首个CIO网站 CIOage 中国首家数字医疗网站 HC3i 移动互联网生活门户 灵客风LinkPhone