VB动态图形按钮的实现
?牐犓枷敕椒ǎ和夹伟磁ヒ訧mage控件来实现;对每一个按钮准备两幅图片,一幅用于正常显示,一幅用于当鼠标指向按钮时显示;这些图片按顺序存放于ImageList控件中。下面是演示程序界面构成及代码:
#1?牐犚?.界面构成
?牐?1. Form主窗体
?牐燦ame:Form1
?牐燙aption:动态图形按钮演示
?牐燘ackColor:&H80000005&?煟ò咨???
?牐?2.Label用于显示选择哪一个按钮
?牐燦ame:Label1
?牐?3.ImageList控件用于存储图片,ImageList 属于控件组Microsoft Windows Common Controls 5.0 (COMCTL32.OCX)中的一个。
?牐牥延糜诎磁サ耐计此承虼娣旁贗mageList中。
?牐?4.Image控件用于显示图像
?牐牬唇↖mage数组Image1(1)-Image1(4)??
#1?牐牰⒋胧迪?
?牐燚im butStatus?煟?1 To 4)?? As Boolean '按钮的状态数组
?牐燚im butMessage?煟?1 To 4)?? As String '提示信息数组
?牐燩rivate Sub Form_Load()?煟?
?牐燚im i As Integer
?牐燜or i = 1 To 4
?牐營mage1(i).Picture = ImageList1.ListImages(2 * i - 1).Picture
?牐燽utStatus(i) = False
?牐燦ext
?牐燽utMessage(1) = “点击了圆形按钮”
?牐燽utMessage(2) = “点击了房子按钮”
?牐燽utMessage(3) = “点击了鲜花按钮”
?牐燽utMessage(4) = “点击了退出按钮”
?牐燛nd Sub
?牐燩rivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)??
?牐燜or i = 1 To 4
?牐營f butStatus(i)?? Then
?牐營mage1?煟╥).Picture = ImageList1.ListImages(2 * i - 1).Picture
?牐燽utStatus(i) = False
?牐燛nd If
?牐燦ext
?牐燛nd Sub
?牐燩rivate Sub Image1_Click(Index As Integer)??
?牐燣abel1.Caption = butMessage(Index)??
?牐燘eep
?牐燛nd Sub
?牐燩rivate Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)??
?牐營f Not butStatus(Index) Then
?牐營mage1(Index).Picture = ImageList1.ListImages(Index * 2).Picture
?牐燽utStatus(Index) = True
?牐燛nd If
?牐燛nd Sub
?牐牨境绦蛟赩B6.0下通过,运行时界面如下:(^16020501a^)