首页 > 编程 > .NET > 正文

VB.NET实现PhotoShop的流动选取框

2024-07-10 13:01:31
字体:
来源:转载
供稿:网友
国内最大的酷站演示中心!
大家好,本人第一次发表文章(激动中),看了开发高手连续几篇谈到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编译通过

有不对的地方请指点
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表