VERSION 5.00
Begin VB.UserControl Button 
   ClientHeight    =   744
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   1344
   ScaleHeight     =   744
   ScaleWidth      =   1344
   ToolboxBitmap   =   "UserControl1.ctx":0000
   Begin VB.CommandButton Command1 
      Caption         =   "Button"
      Height          =   732
      Left            =   0
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   0
      Width           =   1332
   End
End
Attribute VB_Name = "Button"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Dim Temp As String, Code As String, DataString As String 'trial variables
Dim hwndDest As Long
Dim ButtonHoverPicture As Picture
Dim ButtonHoverBackColor As OLE_COLOR
Dim ButtonDownBackColor As OLE_COLOR
Dim OriginalBackColor As OLE_COLOR
Dim OriginalPicture As Picture
Dim OriginalCaption As String
Dim IsHoverColor As Boolean, IsHoverPicture As Boolean, IsHoverCaption As Boolean
Dim IsKeyDown As Boolean
Dim ButtonHoverCaption As String
Dim ButtonDownCaption As String
'Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
'Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Event Click() 'MappingInfo=UserControl,UserControl,-1,Click
Event KeyDown(KeyCode As Integer, Shift As Integer) 'MappingInfo=UserControl,UserControl,-1,KeyDown
Event KeyPress(KeyAscii As Integer) 'MappingInfo=UserControl,UserControl,-1,KeyPress
Event KeyUp(KeyCode As Integer, Shift As Integer) 'MappingInfo=UserControl,UserControl,-1,KeyUp
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
Private Sub Command1_Click()
RaiseEvent Click
End Sub

Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
If Not IsKeyDown Then
 Command1.Caption = ButtonDownCaption
 Command1.BackColor = ButtonDownBackColor
 Command1.Picture = Command1.DownPicture
 IsKeyDown = True
End If
RaiseEvent KeyDown(KeyCode, Shift)
End Sub

Private Sub Command1_KeyPress(KeyAscii As Integer)
RaiseEvent KeyPress(KeyAscii)
End Sub

Private Sub Command1_KeyUp(KeyCode As Integer, Shift As Integer)
IsKeyDown = False
StopHover
RaiseEvent KeyUp(KeyCode, Shift)
End Sub

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
 Command1.Caption = ButtonDownCaption
 Command1.BackColor = ButtonDownBackColor
 Command1.Picture = Command1.DownPicture
End If
RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
sysControlHighLight X, Y, Button
RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
StopHover
RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub

Private Sub UserControl_ExitFocus()
StopHover
End Sub
Function StopHover()
IsKeyDown = False
ReleaseCapture
  With Command1
  If IsHoverColor Then
   If .BackColor <> OriginalBackColor Then .BackColor = OriginalBackColor
  End If
  If IsHoverPicture Then
   If .Picture <> OriginalPicture Then Set .Picture = OriginalPicture
  End If
  If IsHoverCaption Then
   If .Caption <> OriginalCaption Then .Caption = OriginalCaption
  End If
End With
End Function
Private Sub UserControl_Initialize()
ButtonHoverBackColor = &H8000000F
ButtonDownBackColor = &H8000000F
Set ButtonHoverPicture = Command1.Picture
IsKeyDown = False
End Sub
Private Sub sysControlHighLight(X As Single, Y As Single, Button)
On Error Resume Next
If (IsKeyDown) Or (Button > 0) Then Exit Sub
With Command1
 If (X < 0) Or (Y < 0) Or (X > UserControl.Width) Or (Y > UserControl.Height) Then
  ReleaseCapture
  If IsHoverColor Then
   If .BackColor <> OriginalBackColor Then .BackColor = OriginalBackColor
  End If
  If IsHoverPicture Then
   If .Picture <> OriginalPicture Then Set .Picture = OriginalPicture
  End If
 If IsHoverCaption Then
   If .Caption <> OriginalCaption Then .Caption = OriginalCaption
  End If
 Else
  SetCapture .hwnd
  If IsHoverColor Then
   If .BackColor <> ButtonHoverBackColor Then .BackColor = ButtonHoverBackColor
  End If
  If IsHoverPicture Then
   If .Picture <> ButtonHoverPicture Then Set .Picture = ButtonHoverPicture
  End If
  If IsHoverCaption Then
   If .Caption <> ButtonHoverCaption Then .Caption = ButtonHoverCaption
  End If
 End If
End With
On Error GoTo 0
End Sub

Private Sub UserControl_Resize()
Command1.Width = UserControl.Width
Command1.Height = UserControl.Height
End Sub
Public Property Get HoverBackColor() As OLE_COLOR
    HoverBackColor = ButtonHoverBackColor
End Property
Public Property Get DownBackColor() As OLE_COLOR
    DownBackColor = ButtonDownBackColor
End Property
Public Property Get BackColor() As OLE_COLOR
    BackColor = Command1.BackColor
End Property
Public Property Let HoverBackColor(ByVal New_HoverBackColor As OLE_COLOR)
ButtonHoverBackColor = New_HoverBackColor
PropertyChanged "HoverBackColor"
End Property
Public Property Let DownBackColor(ByVal New_DownBackColor As OLE_COLOR)
ButtonDownBackColor = New_DownBackColor
PropertyChanged "DownBackColor"
End Property
Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
    Command1.BackColor() = New_BackColor
    PropertyChanged "BackColor"
End Property

Public Property Get Enabled() As Boolean
    Enabled = Command1.Enabled
End Property

Public Property Let Enabled(ByVal New_Enabled As Boolean)
    Command1.Enabled() = New_Enabled
    PropertyChanged "Enabled"
End Property

Public Property Get Font() As Font
    Set Font = Command1.Font
End Property
Public Property Set Picture(ByVal New_Picture As Picture)
Set Command1.Picture = New_Picture
    PropertyChanged "Picture"
End Property
Public Property Set HoverPicture(ByVal New_HoverPicture As Picture)
Set ButtonHoverPicture = New_HoverPicture
PropertyChanged "HoverPicture"
End Property
Public Property Set DisabledPicture(ByVal New_DisabledPicture As Picture)
    Set Command1.DisabledPicture = New_DisabledPicture
    PropertyChanged "DisabledPicture"
End Property
Public Property Get Picture() As Picture
     Set Picture = Command1.Picture
End Property
Public Property Get HoverPicture() As Picture
     Set HoverPicture = ButtonHoverPicture
End Property
Public Property Get DisabledPicture() As Picture
     Set DisabledPicture = Command1.DisabledPicture
End Property
Public Property Set Font(ByVal New_Font As Font)
    Set Command1.Font = New_Font
    PropertyChanged "Font"
End Property
Public Property Get DownPicture() As Picture
     Set DownPicture = Command1.DownPicture
End Property
Public Property Set DownPicture(ByVal New_DownPicture As Picture)
    Set Command1.DownPicture = New_DownPicture
    PropertyChanged "DownPicture"
End Property

Public Property Get MousePointer() As MousePointerConstants
    MousePointer = Command1.MousePointer
End Property
Public Property Let MousePointer(ByVal New_MousePointer As MousePointerConstants)
    Command1.MousePointer() = New_MousePointer
    PropertyChanged "MousePointer"
End Property
Public Property Get MouseIcon() As Picture
    Set MouseIcon = Command1.MouseIcon
End Property

Public Property Set MouseIcon(ByVal New_MouseIcon As Picture)
    Set Command1.MouseIcon() = New_MouseIcon
    PropertyChanged "MouseIcon"
End Property
Public Property Let HoverCaption(ByVal New_HoverCaption As String)
    ButtonHoverCaption = New_HoverCaption
    PropertyChanged "HoverCaption"
End Property
Public Property Let DownCaption(ByVal New_DownCaption As String)
    ButtonDownCaption = New_DownCaption
    PropertyChanged "DownCaption"
End Property
Public Property Get HoverCaption() As String
   HoverCaption = ButtonHoverCaption
End Property
Public Property Get Caption() As String
    Caption = Command1.Caption
End Property

Public Property Let Caption(ByVal New_Caption As String)
    Command1.Caption() = New_Caption
    PropertyChanged "Caption"
End Property
Public Property Get DownCaption() As String
   DownCaption = ButtonDownCaption
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Command1.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
    ButtonHoverBackColor = PropBag.ReadProperty("HoverBackColor", &H8000000F)
    ButtonDownBackColor = PropBag.ReadProperty("DownBackColor", &H8000000F)
    Command1.Enabled = PropBag.ReadProperty("Enabled", True)
    Set Font = PropBag.ReadProperty("Font", Ambient.Font)
    Set Picture = PropBag.ReadProperty("Picture", "")
    Set DisabledPicture = PropBag.ReadProperty("DisabledPicture", "")
    Set DownPicture = PropBag.ReadProperty("DownPicture", "")
    Set HoverPicture = PropBag.ReadProperty("HoverPicture", LoadPicture())
    Command1.MousePointer = PropBag.ReadProperty("MousePointer", 0)
    Set MouseIcon = PropBag.ReadProperty("MouseIcon", "")
    Command1.Caption = PropBag.ReadProperty("Caption", "Button")
    ButtonHoverCaption = PropBag.ReadProperty("HoverCaption", "Button")
    ButtonDownCaption = PropBag.ReadProperty("DownCaption", "Button")
End Sub



Private Sub UserControl_Show()
'On Error GoTo ErrorHandler
OriginalCaption = Command1.Caption
OriginalBackColor = Command1.BackColor
If Command1.Picture = Null Then
 OriginalPicture = Null
Else
 Set OriginalPicture = Command1.Picture
End If
If (OriginalBackColor <> ButtonHoverBackColor) _
Or (OriginalBackColor <> ButtonDownBackColor) Then
 IsHoverColor = True
Else
 IsHoverColor = False
End If
If OriginalCaption <> ButtonHoverCaption _
Or OriginalCaption <> ButtonDownCaption Then
 IsHoverCaption = True
Else
 IsHoverCaption = False
End If
 If OriginalPicture <> ButtonHoverPicture _
 Or Command1.DownPicture = Null Then
  IsHoverPicture = True
 Else
  IsHoverPicture = False
 End If

'ErrorHandler:
End Sub
Public Sub AboutBox()
Attribute AboutBox.VB_UserMemId = -552
MsgBox "This Control Is FreeWare. If you got any questions or suggestions E-mail us to VBActiveX@hotmail.com" + Chr(13) + "Check For Updates and new controls at Go.To/VBHelp", , "About this control"
End Sub


Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("BackColor", Command1.BackColor, &H8000000F)
    Call PropBag.WriteProperty("HoverBackColor", ButtonHoverBackColor, &H8000000F)
    Call PropBag.WriteProperty("DownBackColor", ButtonDownBackColor, &H8000000F)
    Call PropBag.WriteProperty("Enabled", Command1.Enabled, True)
    Call PropBag.WriteProperty("Font", Font, Ambient.Font)
    Call PropBag.WriteProperty("Picture", Picture, "")
    Call PropBag.WriteProperty("HoverPicture", HoverPicture, "")
    Call PropBag.WriteProperty("DisabledPicture", DisabledPicture, "")
    Call PropBag.WriteProperty("DownPicture", DownPicture, "")
    Call PropBag.WriteProperty("MousePointer", Command1.MousePointer, 0)
    Call PropBag.WriteProperty("MouseIcon", Command1.MouseIcon, "")
    Call PropBag.WriteProperty("Caption", Command1.Caption, "Button")
    Call PropBag.WriteProperty("HoverCaption", HoverCaption, "Button")
    Call PropBag.WriteProperty("DownCaption", DownCaption, "Button")
End Sub


