明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

VB.NET完成PhotoShop的流動(dòng)選取框

[摘要]大家好,本人第一次發(fā)表文章(激動(dòng)中),看了開發(fā)高手連續(xù)幾篇談到PhotoShop中流動(dòng)選取框的文章,其實(shí)實(shí)現(xiàn)并不難,在這里我就用VB.NET實(shí)現(xiàn),在.NET中提供了功能十分強(qiáng)大的GDI+,前篇C#用...
大家好,本人第一次發(fā)表文章(激動(dòng)中),看了開發(fā)高手連續(xù)幾篇談到PhotoShop中流動(dòng)選取框的文章,其實(shí)實(shí)現(xiàn)并不難,在這里我就用VB.NET實(shí)現(xiàn),在.NET中提供了功能十分強(qiáng)大的GDI+,前篇C#用的也是GDI+,我這里也用上!其實(shí)沒有什么區(qū)別!希望對(duì)學(xué)VB.NET的人有幫助,下面是源碼:

創(chuàng)建一個(gè)新的VB應(yīng)用程序,一個(gè)窗口中添加一個(gè)時(shí)間(Timer)組件,Interval設(shè)置為50微妙,

Imports System.Drawing.Drawing2D
Imports System.Drawing.Graphics
Public Class Form1
Inherits System.Windows.Forms.Form
Private pen As pen '創(chuàng)建一個(gè)畫筆對(duì)象
Private GPath As New GraphicsPath '實(shí)例化路徑對(duì)象
Private Dpattern() As Single = {5.0, 7.0} '實(shí)線的長度和虛線長度
Private offset As Single = 0.0 '偏移值

#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "

Public Sub New()
MyBase.New()

'該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。
InitializeComponent()

'在 InitializeComponent() 調(diào)用之后添加任何初始化

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 窗體設(shè)計(jì)器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下過程是 Windows 窗體設(shè)計(jì)器所必需的
'可以使用 Windows 窗體設(shè)計(jì)器修改此過程。
'不要使用代碼編輯器修改它。
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 '設(shè)置偏移值
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) '添加一個(gè)字符路徑
pen = New Pen(Color.Black) '構(gòu)造畫筆
pen.DashPattern = Dpattern '自定義的短劃線和空白區(qū)域
pen.DashStyle = DashStyle.Custom '此屬性的 DashStyle.Custom 值指定:由 DashPattern 屬性定義的短劃線和空白區(qū)域的自定義圖案
End Sub
End Class
在WINXP+SP1+VS.NET2003編譯通過

有不對(duì)的