用VB制作平面按钮
?牐犜赩B的控件Microsoft Windows Common Controls 6.0中StatuBar可以是平面、凸起、凹下三种状态,可以显示文字和小图片,并可根据你的需要调整它们的位置,我们可以通过检测鼠标位置来改变它的不同的外观──鼠标光标不在按钮区时显示平面状态;鼠标光标在按钮区时显示凸起状态;鼠标按下时显示凹下状态。好,现在我们开始。(^46020504a^)
?牐犘陆ㄒ还こ蹋诖疤錐orm1中添加以下控件:
?牐犜诖疤宕肭砣胍韵麓耄?
?牐燨ption Explicit
?牐牐?鼠标信息的API函数定义
?牐燩rivate Declare Function ScreenToClient Lib “user32” (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
?牐燩rivate Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As Long
?牐牐?鼠标指针类型定义
?牐燩rivate Type POINTAPI
?牐爔 As Long
?牐爕 As Long
?牐燛nd Type
?牐燚im Pnt As POINTAPI '用于记录鼠标位置的全局变量
?牐燩rivate Sub Form_Load()
?牐燱ith StatusBar1
?牐牐С9孀刺挛矫?
?牐?.Panels(1).Bevel = sbrNoBevel
?牐?.Panels(1).Text = “平面按钮”
?牐牐ё旨巴计南允疚恢茫簊brLeft图左字左;sbrCenter图左字中;sbrRight图右字右
?牐?.Panels(1).Alignment = sbrCenter
?牐牐ё叭氤9孀刺碌陌磁ネ急?
?牐?.Panels(1).Picture = ImageList1.ListImages(1).Picture
?牐牐?使StatusBar添满容器Picture
?牐?.Width = Picture1.Width
?牐?.Height = Picture1.Height + 30
?牐?.Top = -30 '消除上方的“边”
?牐?.Left = 0
?牐牐е皇褂肧tatusBar的第一个窗格(^46020504b^)
?牐?.Panels(1).Width = .Width
?牐燛nd With
?牐燛nd Sub
?牐燩rivate Sub StatusBar1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)??
?牐牐ё叭朐谑蟊臧聪率钡耐急瓴⑾允疚枷碌淖刺?
?牐燬tatusBar1.Panels(1).Picture = ImageList1.ListImages(3).Picture
?牐燬tatusBar1.Panels(1).Bevel = sbrInset
?牐燭imer1.Enabled = False '关闭鼠标位置检测
?牐燛nd Sub
?牐燩rivate Sub StatusBar1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
?牐牐У笔蟊晔状我迫氚磁デ保羰蟊晡恢眉觳?
?牐營f StatusBar1.Panels(1).Bevel = sbrNoBevel Then Timer1.Enabled = True
?牐燛nd Sub
?牐燩rivate Sub StatusBar1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
?牐牐Щ指窗磁ネ急瓴⑾允疚蛊鸬淖刺?
?牐燬tatusBar1.Panels(1).Picture = ImageList1.ListImages(2).Picture
?牐燬tatusBar1.Panels(1).Bevel = sbrRaised
?牐燭imer1.Enabled = True
?牐燛nd Sub
?牐燩rivate Sub Timer1_Timer()
?牐燝etCursorPos Pnt '得到当前鼠标位置
?牐燬creenToClient Picture1.hwnd, Pnt '转化成相对Picture的相对位置
?牐燱ith StatusBar1
?牐牐Ф允蟊晡恢檬欠裨诎磁デ屑觳?
?牐營f Pnt.x < Picture1.ScaleLeft Or Pnt.y < Picture1.ScaleTop Or Pnt.x > Picture1.ScaleLeft + Picture1.Width /15 Or Pnt.y > Picture1.ScaleTop + Picture1.Height /15 Then
?牐牐?鼠标离开时恢复按钮状态并关闭检测
?牐?.Panels(1).Picture = ImageList1.ListImages(1).Picture
?牐?.Panels(1).Bevel = sbrNoBevel
?牐燭imer1.Enabled = False
?牐燛lse
?牐牐ё叭朐谑蟊暌迫胧钡耐急瓴⑾允疚蛊鸬淖刺?
?牐?.Panels(1).Picture = ImageList1.ListImages(2).Picture
?牐?.Panels(1).Bevel = sbrRaised
?牐燛nd If
?牐燛nd With
?牐燛nd Sub
?牐牫绦虻酱宋梗行巳さ呐笥巡环两诵闯勺约旱目丶院缶涂梢越背砂磁サザ朗褂昧恕R陨洗朐赪indows Me/VB 6.0环境下调试通过。