用下面的程序做数个VB模拟按钮,但在使用中遇到问题:picture边缘只有左边和上边有颜色,右边和下边没有。
还有按钮出现后,颜色与PICTURE的颜色不符,无法回复初始(未加载模拟按钮)状态。请教高手帮忙修改:一、如何在Form_MouseMove()时恢复原始(未加载模拟按钮时)状态。
二、如何让四边同时带色边,这样才更像一个按钮。
Private Sub DrawButton(ob As Object, an As Integer, tu As Integer)
Dim A As Integer
Dim B As Integer
A = ob.Width
B = ob.Height
ob.Line (0, 0)-(A, 0), QBColor(an)
ob.Line (0, 0)-(0, B), QBColor(an)
ob.Line (A, 0)-(A, B), QBColor(tu)
ob.Line (0, B)-(A, B), QBColor(tu)
End SubPrivate Sub Picture10_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Call DrawButton(Picture10(Index), 15, 0) ' tu
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 6
Call DrawButton(Picture10(i), 8, 8) ' tu
Next
For k = 0 To 3
Call DrawButton(Picture2(k), 8, 8) ' tu
Next
End Sub
还有按钮出现后,颜色与PICTURE的颜色不符,无法回复初始(未加载模拟按钮)状态。请教高手帮忙修改:一、如何在Form_MouseMove()时恢复原始(未加载模拟按钮时)状态。
二、如何让四边同时带色边,这样才更像一个按钮。
Private Sub DrawButton(ob As Object, an As Integer, tu As Integer)
Dim A As Integer
Dim B As Integer
A = ob.Width
B = ob.Height
ob.Line (0, 0)-(A, 0), QBColor(an)
ob.Line (0, 0)-(0, B), QBColor(an)
ob.Line (A, 0)-(A, B), QBColor(tu)
ob.Line (0, B)-(A, B), QBColor(tu)
End SubPrivate Sub Picture10_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Call DrawButton(Picture10(Index), 15, 0) ' tu
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 6
Call DrawButton(Picture10(i), 8, 8) ' tu
Next
For k = 0 To 3
Call DrawButton(Picture2(k), 8, 8) ' tu
Next
End Sub
Dim A As Integer
Dim B As Integer
A = ob.Width - Screen.TwipsPerPixelX * 5
B = ob.Height - Screen.TwipsPerPixelX * 5
ob.Line (0, 0)-(A, 0), QBColor(an)
ob.Line (0, 0)-(0, B), QBColor(an)
ob.Line (A, 0)-(A, B), QBColor(tu)
ob.Line (0, B)-(A, B), QBColor(tu)
End Sub
Sub Picture10_LostFocus(Index As Integer)
Call DrawButton(Picture10(Index), 8, 8) ' tu
End Sub
Sub Picture2_LostFocus(Index As Integer)
Call DrawButton(Picture2(Index), 8, 8) ' tu
End SubPrivate Sub Picture10_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Picture10(Index).SetFocus
Call DrawButton(Picture10(Index), 15, 0) ' tu
End If
End Sub
Private Sub Picture2_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Picture2(Index).SetFocus
Call DrawButton(Picture2(Index), 15, 0) ' tu
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 6
Call DrawButton(Picture10(i), 8, 8) ' tu
Next
For k = 0 To 3
Call DrawButton(Picture2(k), 8, 8) ' tu
Next
End Sub
ps:在vb.net中就有mouseleave事件了。
试过了替换图片是达不到这样好的效果的。继续请各位大侠看一下:我的picture按钮颜色为天蓝色,但是QBColor(color) color 参数是一个界于 0 到 15 的整型,没有天蓝色。我希望当FORM_MOUSEMOVE时,能够让picture边缘回复天蓝色(与FORM背景色一样的颜色),做到按钮边缘无缝无线条。
可以得到256*256*256种颜色
在这里好像没法改成RGB()?
Option ExplicitPrivate Sub Form_Load()
Image1.Picture = LoadPicture("C:\Background Images\Background_1.gif")
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Picture = LoadPicture("C:\Background Images\Background_1.gif")
End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Picture = LoadPicture("C:\Background Images\Background_2.gif")
End Sub
但是出来一点小问题:当form_mousemove并离开picture_mousemove10(0)到新的按钮picture_mousemove10(1)时,picture_mousemove10(0)的右边和下边还有按钮的边缘颜色,要跨到下下个按钮才能消除。
这个如何解决?是哪里有问题?Private Sub DrawButton(ob As Object, r As Integer, g As Integer, bs As Integer, rr As Integer, gg As Integer, bb As Integer)
Dim A As Integer
Dim b As Integer
A = ob.Width - Screen.TwipsPerPixelX
b = ob.Height - Screen.TwipsPerPixelX
ob.Line (0, 0)-(A, 0), RGB(r, g, bs)
ob.Line (0, 0)-(0, b), RGB(r, g, bs)
ob.Line (A, 0)-(A, b), RGB(rr, gg, bb)
ob.Line (0, b)-(A, b), RGB(rr, gg, bb)
End Sub
Sub Picture10_LostFocus(Index As Integer)
Call DrawButton(Picture10(Index), 121, 202, 255, 182, 184, 194)
End Sub
Sub Picture2_LostFocus(Index As Integer)
Call DrawButton(Picture2(Index), 121, 202, 255, 182, 184, 194)
End SubPrivate Sub Picture10_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Picture10(Index).SetFocus
Call DrawButton(Picture10(Index), 255, 255, 255, 182, 184, 194)
End If
End Sub
Private Sub Picture2_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Picture2(Index).SetFocus
Call DrawButton(Picture2(Index), 255, 255, 255, 182, 184, 194)
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 6
Call DrawButton(Picture10(i), 121, 202, 255, 121, 202, 255) '
Next
For k = 0 To 3
Call DrawButton(Picture2(k), 121, 202, 255, 121, 202, 255) '
Next
End Sub
因为你没给 Picture10 原始的 颜色配置, 边框配置
当然我只能用预设颜色灰色表示
Dim A As Integer
Dim B As Integer
A = ob.Width - Screen.TwipsPerPixelX * 5
B = ob.Height - Screen.TwipsPerPixelX * 5
ob.Line (0, 0)-(A, 0), (an)
ob.Line (0, 0)-(0, B), (an)
ob.Line (A, 0)-(A, B), (tu)
ob.Line (0, B)-(A, B), (tu)
End SubPrivate Sub Form_Load()
Me.BackColor = &HFF9900
For i = 0 To 6
Picture10(i).BorderStyle = 0
Picture10(i).BackColor = Me.BackColor
Next
For i = 0 To 3
Picture2(i).BorderStyle = 0
Picture2(i).BackColor = Me.BackColor
Next
End SubSub Picture10_LostFocus(Index As Integer)
Call DrawButton(Picture10(Index), Me.BackColor, Me.BackColor) ' tu
End Sub
Sub Picture2_LostFocus(Index As Integer)
Call DrawButton(Picture2(Index), Me.BackColor, Me.BackColor) ' tu
End SubPrivate Sub Picture10_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Picture10(Index).SetFocus
Call DrawButton(Picture10(Index), &HDDDDDD, 0) ' tu
End If
End Sub
Private Sub Picture2_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then
Picture2(Index).SetFocus
Call DrawButton(Picture2(Index), &HDDDDDD, 0) ' tu
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 6
Call DrawButton(Picture10(i), Me.BackColor, Me.BackColor) ' tu
Next
For k = 0 To 3
Call DrawButton(Picture2(k), Me.BackColor, Me.BackColor) ' tu
Next
End Sub
【CBM666 的按钮特效】
http://cbm666.net/forum.php?mod=viewthread&tid=1789&fromuid=2