用VB 4.0实现多功能按钮
VERSION 4.00
Begin VB.Form Form1
Caption= ”buttons”
Begin VB.PictureBox Picture1
BackColor=&H00FFFFFF&
TabIndex=1
End
Begin VB.PictureBox Picture2
BackColor=&H00FF0000&
TabIndex=0
End
End
Option Explicit
Dim pic-x As Integer
Dim pic-y As Integer
Function delay(ByVal time As Integer)Dim j As Integer
j=0
Do While j<time
j=j+1
Loop
End Function
Sub Form-Load()
pic-x=picture2.Left
pic-y=Picture2.TOP
End Sub
Sub Picture1-MouseDown(Button As Integer,shift As Integer
X As Single,Y As Single
static i as integer
If Button=1 Then
If(Pic-x<>Picture2.Left)And(Pic-y<>Picture2.Top)
Then
Form1.Picture2.Move Picture2.Left+200,Picture2.Top+200
i=i+1
Select Case i Mod 4
Case 0
Picture1.Picture=
LoadPicture(”c:\vb\icons\computer\pc04.ico”)
Case 1
Picture1.Picture=
LoadPicture(”c:\vb\icons\computer\pc01.ico”)
Case 2
Picture1.Picture=
LoadPicture(”c:\vb\icons\computer\pc02.ico”)
Case 3
Picture1.Picture=
LoadPicture(”c:\vb\icons\computer\pc03.co”)
End Select
Else
Form1.Picture2.Move Picture2.Left-200,Picture2.Top-200
End If
End If
If Button=2 Then
Do While DoEvents
Picture1.BackColor=&HFF0000
delay (6000)
Picture1.BackColor=&HFFFFFF
Loop
End If
End Sub
分析:本程序用了两个Picturebox遮叠,实现了虚拟式阴影效果,但只能在Picture1中移动Picture2,其它方法笔者都一一试过而无法通过;另外在实现闪烁时在循环语句中用了函数Doevents使程序不至于死循环。