codice:
VERSION 5.00
Begin VB.UserControl RoundButton
BackStyle = 0 'Transparent
ClientHeight = 1500
ClientLeft = 0
ClientTop = 0
ClientWidth = 1515
ScaleHeight = 1500
ScaleWidth = 1515
Begin VB.Label lblcaption
Alignment = 2 'Center
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "Label1"
Height = 195
Left = 495
TabIndex = 0
Top = 630
Width = 480
End
Begin VB.Shape shpArea
BackStyle = 1 'Opaque
Height = 1215
Left = 120
Shape = 2 'Oval
Top = 120
Width = 1230
End
End
Attribute VB_Name = "RoundButton"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Dim act_ClickColor
Dim act_BackColor
Dim act_BorderColor
Public Event Click()
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Private Sub UserControl_InitProperties()
Caption = Ambient.DisplayName
ClickColor = &HDDDDDD
BorderColor = &H0&
BackColor = &HFFFFFF
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpArea.BackColor = ClickColor
RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpArea.BackColor = BackColor
RaiseEvent MouseUp(Button, Shift, X, Y)
RaiseEvent Click
End Sub
Private Sub lblCaption_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpArea.BackColor = ClickColor
RaiseEvent MouseDown(Button, Shift, lblcaption.Left + X, lblcaption.Top + Y)
End Sub
Private Sub lblCaption_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpArea.BackColor = BackColor
RaiseEvent MouseUp(Button, Shift, lblcaption.Left + X, lblcaption.Top + Y)
RaiseEvent Click
End Sub
Private Sub lblcaption_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, lblcaption.Left + X, lblcaption.Top + Y)
End Sub
Private Sub UserControl_Resize()
shpArea.Move 0, 0, ScaleWidth, ScaleHeight
lblcaption.Move (ScaleWidth - lblcaption.Width) / 2, (ScaleHeight - lblcaption.Height) / 2
End Sub
Property Let Caption(ByVal NewCaption As String)
lblcaption.Caption = NewCaption
UserControl_Resize
End Property
Property Get Caption() As String
Caption = lblcaption.Caption
End Property
Property Let BackColor(ByVal NewColor As OLE_COLOR)
shpArea.BackColor = NewColor
act_BackColor = NewColor
PropertyChanged "BackColor"
End Property
Property Get BackColor() As OLE_COLOR
BackColor = act_BackColor
End Property
Property Let BorderColor(ByVal NewColor As OLE_COLOR)
shpArea.BorderColor = NewColor
act_BorderColor = NewColor
PropertyChanged "BorderColor"
End Property
Property Get BorderColor() As OLE_COLOR
BorderColor = act_BorderColor
End Property
Property Let ClickColor(ByVal NewColor As OLE_COLOR)
act_ClickColor = NewColor
PropertyChanged "ClickColor"
End Property
Property Get ClickColor() As OLE_COLOR
ClickColor = act_ClickColor
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
BackColor = PropBag.ReadProperty("BackColor", &HFFFFFF)
BorderColor = PropBag.ReadProperty("BorderColor", &H0&)
ClickColor = PropBag.ReadProperty("ClickColor", &HDDDDDD)
Caption = PropBag.ReadProperty("Caption", Ambient.DisplayName)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "BackColor", act_BackColor, &HFFFFFF
PropBag.WriteProperty "BorderColor", act_BorderColor, &H0&
PropBag.WriteProperty "ClickColor", act_ClickColor, &HDDDDDD
PropBag.WriteProperty "Caption", lblcaption.Caption, Ambient.DisplayName
End Sub
ovviamente le caratteristiche che ha sono molto scarne, ma puoi personalizzarlo a piacere.