当前位置:主页   - 电脑 - 网站开发 - ASP.Net
VB.NET实现PhotoShop的流动选取框
来源:网上收集   作者:未知   更新时间:2009-02-23
收藏此页】    【字号    】    【打印】    【关闭
大家好,本人第一次发表文章(激动中),看了开发高手连续几篇谈到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编译通过

有不对的地方请指点

其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明