实现浮动按钮

王朝vb·作者佚名  2006-01-08
宽屏版  字体: |||超大  

程序里面使用了浮动按钮,可以使程序看起来更美观和更容易使用。实现的方法是首先建立四条Line。和一个Image的控件,在程序根目录下把图标先改成macos.ico或者把程序相应更改一下图标文件的名字。然后代码如下:

Private Sub Form_Load()

Image1.Picture = LoadPicture(App.Path & "\macos.ico")

'使Line控件不可见

Line1.Visible = False

Line2.Visible = False

Line3.Visible = False

Line4.Visible = False

'调整Line1控件在Image1的左边,并调整大小

Line1.X1 = Image1.Left - 1

Line1.Y1 = Image1.Top - 1

Line1.X2 = Line1.X1

Line1.Y2 = Image1.Top + Image1.Height + 1

'调整Line2控件在Image1的上面,并调整大小

Line2.X1 = Image1.Left - 1

Line2.Y1 = Image1.Top - 1

Line2.X2 = Image1.Top + Image1.Height + 1

Line2.Y2 = Line1.Y1

'调整Line3控件在Image1的右边,并调整大小

Line3.X1 = Line2.X2

Line3.Y1 = Line2.Y1

Line3.X2 = Line2.X2

Line3.Y2 = Line1.Y2

'调整Line4控件在Image1的下面,并调整大小

Line4.X1 = Line1.X1

Line4.Y1 = Line1.Y2

Line4.X2 = Line2.X2

Line4.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 = False

Line2.Visible = False

Line3.Visible = False

Line4.Visible = False

Image1.Picture = LoadPicture(App.Path & "\macos.ico")

End If

End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

'左键

If Button = 1 Then

Line1.BorderColor = QBColor(0)

Line2.BorderColor = QBColor(0)

Line3.BorderColor = QBColor(15)

Line4.BorderColor = QBColor(15)

End If

MsgBox "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 = True

Line2.Visible = True

Line3.Visible = True

Line4.Visible = True

Image1.Picture = LoadPicture(App.Path & "\macos.ico")

End If

End Sub

Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

'右键

If Button = 1 Then

Line1.BorderColor = QBColor(15)

Line2.BorderColor = QBColor(15)

Line3.BorderColor = QBColor(0)

Line4.BorderColor = QBColor(0)

End If

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有