首页 > 编程 > .NET > 正文

VB.NET中的Line控件

2024-07-10 13:00:49
字体:
来源:转载
供稿:网友

在vb.net中去掉了line控件,我们用.net转换包含有line控件的vb6的工程后,发现取而代之的是label。

其实我们还可以有另一种画线的方法:

public class line
inherits system.windows.forms.usercontrol
public toplc as system.drawing.color = system.drawing.color.white '上线颜色
public footlc as system.drawing.color = system.drawing.color.black '下线颜色
public linet as type '直线类型
public enum type
tf '凸
ft '凹
flat '平面
end enum
#region " windows 窗体设计器生成的代码 "
public sub new()
mybase.new()
'该调用是 windows 窗体设计器所必需的。
initializecomponent()
'在 initializecomponent() 调用之后添加任何初始化
end sub
'usercontrol 重写 dispose 以清理组件列表。
protected overloads overrides sub dispose(byval disposing as boolean)
if disposing then
if not (components is nothing) then
components.dispose()
end if
end if
mybase.dispose(disposing)
end sub
'windows 窗体设计器所必需的
private components as system.componentmodel.icontainer
'注意: 以下过程是 windows 窗体设计器所必需的
'可以使用 windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<system.diagnostics.debuggerstepthrough()> private sub initializecomponent()
'
'line
'
me.name = "line"
me.size = new system.drawing.size(304, 72)
end sub
#end region
#region " 属性 "
<system.componentmodel.description("直线类型:" & vbcrlf & "tf '凸" & vbcrlf & "ft '凹" & vbcrlf & "flat '平面")> public property linetype() as type
get
linetype = linet
end get
set(byval value as type)
linet = value
end set
end property
<system.componentmodel.description("上线颜色")> public property toplinecolor() as system.drawing.color
get
toplinecolor = toplc
end get
set(byval value as system.drawing.color)
toplc = value
end set
end property
<system.componentmodel.description("下线颜色")> public property footlinecolor() as system.drawing.color
get
footlinecolor = footlc
end get
set(byval value as system.drawing.color)
footlc = value
end set
end property
#end region
private sub line_paint(byval sender as object, byval e as system.windows.forms.painteventargs) handles mybase.paint
dim topline as new pen(me.toplinecolor)
dim footline as new pen(me.footlinecolor)
dim startx as integer
dim starty as integer
select case linet
case linet.flat
e.graphics.drawline(topline, 0 + startx, 0, me.width + startx, 0)
e.graphics.drawline(topline, 1 + startx, 1, me.width + startx, 1)
case linet.tf
e.graphics.drawline(topline, 0 + startx, 0, me.width + startx, 0)
e.graphics.drawline(footline, 1 + startx, 1, me.width + startx, 1)
case linet.ft
e.graphics.drawline(footline, 0 + startx, 0, me.width + startx, 0)
e.graphics.drawline(topline, 1 + startx, 1, me.width + startx, 1)
end select
end sub
private sub line_resize(byval sender as object, byval e as system.eventargs) handles mybase.resize
me.height = 2
end sub
end class



新建一个类,把以上代码粘贴即可。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表