用VB 4.0实现多功能按钮 高道强 1997-01-01   按钮是交互式界面设计中的一个重要部分。VB提供的Command Button按钮对象,虽然很有用,但是随着多媒体的不断发展,这种单调按钮已不能满足这一要求,为此笔者设计了一种多功能图形按钮,它具有以下特点:1)单击鼠标左键时图形按钮弹出,并且按钮界面能够动态地更换多种图形。2)单击鼠标右键时图形按钮能够闪烁不定,颜色交替变换。3)如果左右键同时击,1、2两种特点同时具有。   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使程序不至于死循环。