最简单的办法: 建一个usercontrol,将背景风格(BackStyle属性)设置为透明, 再放上一个Shape1控件,添加如下代码。Option Explicit'事件声明: Event Click() 'MappingInfo=UserControl,UserControl,-1,Click Event DblClick() 'MappingInfo=UserControl,UserControl,-1,DblClick Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseDown Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseMove Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseUp'注意!不要删除或修改下列被注释的行! 'MappingInfo=Shape1,Shape1,-1,BackColor Public Property Get BackColor() As OLE_COLOR BackColor = Shape1.BackColor End PropertyPublic Property Let BackColor(ByVal New_BackColor As OLE_COLOR) Shape1.BackColor() = New_BackColor PropertyChanged "BackColor" End Property'注意!不要删除或修改下列被注释的行! 'MappingInfo=UserControl,UserControl,-1,Enabled Public Property Get Enabled() As Boolean Enabled = UserControl.Enabled End PropertyPublic Property Let Enabled(ByVal New_Enabled As Boolean) UserControl.Enabled() = New_Enabled PropertyChanged "Enabled" End PropertyPrivate Sub UserControl_Click() RaiseEvent Click End SubPrivate Sub UserControl_DblClick() RaiseEvent DblClick End SubPrivate Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) RaiseEvent MouseDown(Button, Shift, X, Y) End SubPrivate Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) RaiseEvent MouseMove(Button, Shift, X, Y) End SubPrivate Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) RaiseEvent MouseUp(Button, Shift, X, Y) End Sub'从存贮器中加载属性值 Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Shape1.BackColor = PropBag.ReadProperty("BackColor", &H80000005) UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
'** 下面的语句可以在设计窗口中指定。 Shape1.Shape = 3 Shape1.BackStyle = 1 Shape1.BorderStyle = 0 End Sub'将属性值写到存储器 Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Call PropBag.WriteProperty("BackColor", Shape1.BackColor, &H80000005) Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True) End Sub如果看不出颜色,你可以修改背景色就可以看到一个圆形的控件了,并且所有鼠标事件仅在此圆形中发生。你还可以加入一个label1控件,来为这个圆形按钮添加一个Caption属性以显示文本。 其实做异形按钮的方法有很多,我认为这是最简单的方法,其他方法你可以参考这个例子,它建立了一个六边形按钮,修改它可以建任意形状的控件。 http://www.vb99.com/loaddown.asp?tid=1&pathid=5&Filenames=61
建一个usercontrol,将背景风格(BackStyle属性)设置为透明, 再放上一个Shape1控件,添加如下代码。Option Explicit'事件声明:
Event Click() 'MappingInfo=UserControl,UserControl,-1,Click
Event DblClick() 'MappingInfo=UserControl,UserControl,-1,DblClick
Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseDown
Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseMove
Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseUp'注意!不要删除或修改下列被注释的行!
'MappingInfo=Shape1,Shape1,-1,BackColor
Public Property Get BackColor() As OLE_COLOR
BackColor = Shape1.BackColor
End PropertyPublic Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
Shape1.BackColor() = New_BackColor
PropertyChanged "BackColor"
End Property'注意!不要删除或修改下列被注释的行!
'MappingInfo=UserControl,UserControl,-1,Enabled
Public Property Get Enabled() As Boolean
Enabled = UserControl.Enabled
End PropertyPublic Property Let Enabled(ByVal New_Enabled As Boolean)
UserControl.Enabled() = New_Enabled
PropertyChanged "Enabled"
End PropertyPrivate Sub UserControl_Click()
RaiseEvent Click
End SubPrivate Sub UserControl_DblClick()
RaiseEvent DblClick
End SubPrivate Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseDown(Button, Shift, X, Y)
End SubPrivate Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
End SubPrivate Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub'从存贮器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Shape1.BackColor = PropBag.ReadProperty("BackColor", &H80000005)
UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
'** 下面的语句可以在设计窗口中指定。
Shape1.Shape = 3
Shape1.BackStyle = 1
Shape1.BorderStyle = 0
End Sub'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Call PropBag.WriteProperty("BackColor", Shape1.BackColor, &H80000005)
Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
End Sub如果看不出颜色,你可以修改背景色就可以看到一个圆形的控件了,并且所有鼠标事件仅在此圆形中发生。你还可以加入一个label1控件,来为这个圆形按钮添加一个Caption属性以显示文本。
其实做异形按钮的方法有很多,我认为这是最简单的方法,其他方法你可以参考这个例子,它建立了一个六边形按钮,修改它可以建任意形状的控件。
http://www.vb99.com/loaddown.asp?tid=1&pathid=5&Filenames=61
然后用IMAGE控件来加载它,在IMAGE控件的CLICK事件中写你的程序代码就可以了,完全和COMMAND一样。