'根据相关文章修改而来。在WindowsXP Spack3.0+VS2008下测试通过。
'新建工程,窗体名称Form1即可。代码粘贴到窗体的代码窗口即可。
Imports System.Drawing.Drawing2D
Imports System.Drawing.Graphics Public Class Form1 Private pen As Pen '创建一个画笔对象 Private GPath As New GraphicsPath '实例化路径对象 Private Dpattern() As Single = {5.0, 7.0} '实线的长度和虚线长度 Private offset As Single = 0.0 '偏移值 Public Sub New()
' 此调用是 Windows 窗体设计器所必需的。
InitializeComponent() ' 在 InitializeComponent() 调用之后添加任何初始化。
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GPath.AddString("电脑", _ New FontFamily("幼圆"), _ FontStyle.Bold + FontStyle.Italic, _ 120.0F, _ New PointF(30.0F, 20.0F), _ New StringFormat) '添加一个字符路径 pen = New Pen(Color.Black) '构造画笔 pen.DashPattern = Dpattern '自定义的短划线和空白区域 pen.DashStyle = DashStyle.Custom '此属性的 DashStyle.Custom 值指定:由 DashPattern 属性定义的短划线和空白区域的自定义图案 End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
pen.DashOffset = offset '‘设置偏移值 e.Graphics.DrawPath(pen, GPath) '‘画路径 '‘改变偏移值的量 offset += 1.0 If offset / 100 = 1 Then offset = 0.0 End If End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Refresh() '‘刷新窗口 End Sub End Class |
|