VB.NET實現PhotoShop的流動選取框 大家好,本人第一次發表文章(激動中),看了開發高手連續幾篇談到PhotoShop中流動選取框的文章,其實實現並不難,在這裡我就用VB.NET實現,在.NET中提供了功能十分強大的GDI+,前篇C#用的也是GDI+,我這裡也用上!其實沒有什麼區別!希望對學VB.NET的人有協助,下面是源碼:建立一個新的VB應用程式,一個視窗中添加一個時間(Timer)組件,Interval設定為50微妙,Imports System.Drawing.Drawing2D
Imports System.Drawing.Graphics
Public Class Form1
Inherits System.Windows.Forms.Form
Private pen As pen '建立一個畫筆對象
Private GPath As New GraphicsPath '執行個體化路徑對象
Private Dpattern() As Single = {5.0, 7.0} '實線的長度和虛線長度
Private offset As Single = 0.0 '位移值#Region " Windows 表單設計器產生的程式碼 " Public Sub New()
MyBase.New() '該調用是 Windows 表單設計器所必需的。
InitializeComponent() '在 InitializeComponent() 調用之後添加任何初始化 End Sub '表單重寫 dispose 以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
GPath.Dispose()
pen.Dispose()
End If
MyBase.Dispose(disposing)
End Sub 'Windows 表單設計器所必需的
Private components As System.ComponentModel.IContainer '注意: 以下過程是 Windows 表單設計器所必需的
'可以使用 Windows 表單設計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 50
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(416, 166)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Photo For VB.NET" End Sub#End Region Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Refresh() '重新整理視窗
End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.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 Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.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
End Class
在WINXP+SP1+VS.NET2003編譯通過