程序里面使用了浮动按钮,可以使程序看起来更美观和更容易使用。实现的方法是首先建立四条Line。和一个Image的控件,在程序根目录下把图标先改成macos.ico或者把程序相应更改一下图标文件的名字。然后代码如下:
Private Sub Form_Load()Image1.Picture = LoadPicture(App.Path & "/macos.ico")
'使Line控件不可见Line1.Visible = FalseLine2.Visible = FalseLine3.Visible = FalseLine4.Visible = False
'调整Line1控件在Image1的左边,并调整大小Line1.X1 = Image1.Left - 1Line1.Y1 = Image1.Top - 1Line1.X2 = Line1.X1Line1.Y2 = Image1.Top + Image1.Height + 1
'调整Line2控件在Image1的上面,并调整大小Line2.X1 = Image1.Left - 1Line2.Y1 = Image1.Top - 1Line2.X2 = Image1.Top + Image1.Height + 1Line2.Y2 = Line1.Y1
'调整Line3控件在Image1的右边,并调整大小Line3.X1 = Line2.X2Line3.Y1 = Line2.Y1Line3.X2 = Line2.X2Line3.Y2 = Line1.Y2
'调整Line4控件在Image1的下面,并调整大小Line4.X1 = Line1.X1Line4.Y1 = Line1.Y2Line4.X2 = Line2.X2Line4.Y2 = Line1.Y2
'按钮凸起效果Line1.BorderColor = QBColor(15) '白色Line2.BorderColor = QBColor(15) '白色Line3.BorderColor = QBColor(0) '黑色Line4.BorderColor = QBColor(0) '黑色End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)If Line1.Visible = True Then'防止无意义调用下列语句Line1.Visible = FalseLine2.Visible = FalseLine3.Visible = FalseLine4.Visible = FalseImage1.Picture = LoadPicture(App.Path & "/macos.ico")End IfEnd Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)'左键If Button = 1 ThenLine1.BorderColor = QBColor(0)Line2.BorderColor = QBColor(0)Line3.BorderColor = QBColor(15)Line4.BorderColor = QBColor(15)End IfMsgBox "Jason guo提醒你!要好好学习VB哦!!!"End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)If Line1.Visible = False Then'防止无意义调用下面语句Line1.Visible = TrueLine2.Visible = TrueLine3.Visible = TrueLine4.Visible = TrueImage1.Picture = LoadPicture(App.Path & "/macos.ico")End IfEnd Sub
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)'右键If Button = 1 ThenLine1.BorderColor = QBColor(15)Line2.BorderColor = QBColor(15)Line3.BorderColor = QBColor(0)Line4.BorderColor = QBColor(0)End IfEnd Sub