-
vb教程之制作VB另类按钮
如果你看腻了VB的中规中矩的按钮,有时想改变一下的话,本文或许对你有所启发。以下二例用Line方法结合其它手段,在窗体上绘制出别具一格的“按钮”,呵呵,还是有那么一点儿新意的(怎么象是吹牛?)。建议在不需要太多的按钮的窗体中使用。
例一:用Line方法制作初始时为平面、鼠标移到时突出的按钮,此类按钮其实更象是第一层菜单,可为之通过Form_MouseDown或者Form_MouseUp编写类似于Click的事件。当然了,用标签+线条或者+ImageBox来实现更简单些。
Private Sub Form_Load()
Me.AutoRedraw = True
CurrentX = 280: CurrentY = 150
Me.Print "Exit"
Me.Caption = "请将鼠标移近文字观察效果"
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If X <= 900 And X >= 100 And Y <= 500 And Y >= 100 Then
End
End If
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X <= 900 And X >= 100 And Y <= 500 And Y >= 100 Then
Me.Caption = "左键单击按钮退出程序"
Line (100, 100)-(100, 400), vbWhite
Line (100, 100)-(800, 100), vbWhite
Line (100, 400)-(800, 400), vbBlack
Line (800, 100)-(800, 425), vbBlack '多出25是为了让右下角更封闭
Me.ForeColor = vbBlue
CurrentX = 280: CurrentY = 150
Me.Print "Exit"
Else
Me.Cls
CurrentX = 280: CurrentY = 150
Me.ForeColor = vbBlack
Me.Print "Exit"
Me.Caption = "请将鼠标移近文字观察效果"
End If
End Sub
例二:用Line方法结合PictureBox(作按钮容器用)制作有立体感的按钮,很Cool哟。要试用本例,请在窗体上缺省绘制一个1000*700的PictureBox控件。
Private Sub Form_Load()
Dim k As Integer
Picture1.AutoRedraw = True
Me.AutoRedraw = True
'绘制出灰度的效果
For k = 0 To 20
Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(255 - 5 * k, 255 - 5 * k, 255 - 5 * k)
Next k
Picture1.CurrentX = 250: Picture1.CurrentY = 250
Picture1.Print "Hello"
End Sub
'绘制矩形
Sub Rect(obj As Object, X As Integer, Y As Integer, iW As Integer, iH As Integer, iC As Long)
obj.Line (X, Y)-(X + iW, Y), iC
obj.Line -Step(0, iH), iC
obj.Line -Step(-iW, 0), iC
obj.Line -Step(0, -iH), iC
End Sub
'鼠标在窗体移动时按钮保持灰度的原貌
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
For k = 0 To 20
Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(255 - 5 * k, 255 - 5 * k, 255 - 5 * k)
Picture1.ForeColor = vbBlack
Picture1.CurrentX = 250: Picture1.CurrentY = 250
Picture1.FontBold = False
Picture1.Print "Hello"
Next k
End Sub
'鼠标移动到图片框时按钮形状发生变化:底色为深色,按钮周边带色彩边框,文字变色
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim k As Integer
For k = 0 To 20
Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(8 * k, 12 * k, 8 * k)
Picture1.ForeColor = vbRed
Picture1.CurrentX = 250: Picture1.CurrentY = 250
Picture1.Print "Hello"
Next
End Sub
例一:用Line方法制作初始时为平面、鼠标移到时突出的按钮,此类按钮其实更象是第一层菜单,可为之通过Form_MouseDown或者Form_MouseUp编写类似于Click的事件。当然了,用标签+线条或者+ImageBox来实现更简单些。
Private Sub Form_Load()
Me.AutoRedraw = True
CurrentX = 280: CurrentY = 150
Me.Print "Exit"
Me.Caption = "请将鼠标移近文字观察效果"
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If X <= 900 And X >= 100 And Y <= 500 And Y >= 100 Then
End
End If
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X <= 900 And X >= 100 And Y <= 500 And Y >= 100 Then
Me.Caption = "左键单击按钮退出程序"
Line (100, 100)-(100, 400), vbWhite
Line (100, 100)-(800, 100), vbWhite
Line (100, 400)-(800, 400), vbBlack
Line (800, 100)-(800, 425), vbBlack '多出25是为了让右下角更封闭
Me.ForeColor = vbBlue
CurrentX = 280: CurrentY = 150
Me.Print "Exit"
Else
Me.Cls
CurrentX = 280: CurrentY = 150
Me.ForeColor = vbBlack
Me.Print "Exit"
Me.Caption = "请将鼠标移近文字观察效果"
End If
End Sub
例二:用Line方法结合PictureBox(作按钮容器用)制作有立体感的按钮,很Cool哟。要试用本例,请在窗体上缺省绘制一个1000*700的PictureBox控件。
Private Sub Form_Load()
Dim k As Integer
Picture1.AutoRedraw = True
Me.AutoRedraw = True
'绘制出灰度的效果
For k = 0 To 20
Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(255 - 5 * k, 255 - 5 * k, 255 - 5 * k)
Next k
Picture1.CurrentX = 250: Picture1.CurrentY = 250
Picture1.Print "Hello"
End Sub
'绘制矩形
Sub Rect(obj As Object, X As Integer, Y As Integer, iW As Integer, iH As Integer, iC As Long)
obj.Line (X, Y)-(X + iW, Y), iC
obj.Line -Step(0, iH), iC
obj.Line -Step(-iW, 0), iC
obj.Line -Step(0, -iH), iC
End Sub
'鼠标在窗体移动时按钮保持灰度的原貌
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
For k = 0 To 20
Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(255 - 5 * k, 255 - 5 * k, 255 - 5 * k)
Picture1.ForeColor = vbBlack
Picture1.CurrentX = 250: Picture1.CurrentY = 250
Picture1.FontBold = False
Picture1.Print "Hello"
Next k
End Sub
'鼠标移动到图片框时按钮形状发生变化:底色为深色,按钮周边带色彩边框,文字变色
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim k As Integer
For k = 0 To 20
Rect Picture1, 5 * k, 5 * k, Picture1.ScaleWidth - 10 * k, Picture1.ScaleHeight - 10 * k, RGB(8 * k, 12 * k, 8 * k)
Picture1.ForeColor = vbRed
Picture1.CurrentX = 250: Picture1.CurrentY = 250
Picture1.Print "Hello"
Next
End Sub
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比