Imports System.Windows.Forms
Imports System.Drawing
Imports System.ComponentModel
Imports System.Collections
'ControlPaint.DrawGrid(P.Graphics, New Rectangle(x, y, Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), New Size(5, 5), Color.Black)
'ControlPaint.DrawSizeGrip(P.Graphics, Color.Black, New Rectangle(x, y, Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height))
'ControlPaint.DrawSelectionFrame(P.Graphics, True, New Rectangle(x, y, Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height) , New Rectangle(x + 2, y + 2, 5, 5), Color.Black)
'ControlPaint.DrawReversibleLine( New Point(x, y), New Point(Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), Color.Black)
'ControlPaint.DrawMenuGlyph(P.Graphics, New Rectangle(x, y, Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), MenuGlyph.Checkmark)
'ControlPaint.DrawContainerGrabHandle(P.Graphics, New Rectangle(x, y, Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height))
'ControlPaint.DrawGrabHandle(P.Graphics, New Rectangle(Me.Location.X + 1, Me.Location.Y + 1, 10, Me.intParent.ButtonSize.Height - 2), True, True)
'ControlPaint.DrawContainerGrabHandle(P.Graphics, New Rectangle(Location.X + 1, Me.Location.Y + 1, 10, Me.intParent.ButtonSize.Height - 2))
'ControlPaint.DrawBorder3D(P.Graphics, 1, 1, Me.Width - 2, Me.Height - 2, Border3DStyle.SunkenInner)
<Designer("BVToolBarBandDesigner"), _
DefaultProperty("Buttons"), _
CLSCompliant(True)> _
Public Class BVToolBarBand
Inherits BVToolBarObjectBase
Private MouseOver As Integer
Protected AList As BVToolBarButtonCollection 'BVArrayList
Protected intImgLst As ImageList
Protected intTrackLenght As Integer
Protected intSeparatorDefaultLenght As Integer
Protected intDropDownDefaultLenght As Integer
Private intBorderStyle As System.Windows.Forms.BorderStyle
Protected DropDownForm As PopUpForm
Private tltipTxt As ToolTipText
Private WithEvents tmr As Timer
Public Event Change(ByVal sender As Object, ByVal e As EventArgs)
Public Event ButtonClick(ByVal sender As Object, ByVal e As BVToolBarButtonClickEventArgs)
Public Event ButtonDropDown(ByVal sender As Object, ByVal e As BVToolBarButtonClickEventArgs)
#Region "Constructor"
Public Sub New()
MyBase.New()
Initialize()
End Sub
Public Sub New(ByVal Name As String)
MyBase.New()
Me.Name = Name
Initialize()
End Sub
Protected Overrides Sub Initialize()
Me.intName = intName
intEnabled = True
AList = New BVToolBarButtonCollection(Me.intParent)
Me.intVisible = True
Me.intEnabled = True
intTrackLenght = 10
intSeparatorDefaultLenght = 10
intDropDownDefaultLenght = 15
MouseOver = -1
intRec = New Rectangle(0, 0, 10, 30)
intBrush = New SolidBrush(Color.LightGray)
tltipTxt = New ToolTipText
If Not Me.intParent Is Nothing Then
tltipTxt.Parent = Me.intParent
End If
tltipTxt.ToolTipStyle = ToolTipText.eToolTipStyle.Default
tltipTxt.Width = 150
tltipTxt.ShowCloseButton = False
tltipTxt.AutoReSize = True
tltipTxt.Delay = 2
tmr = New Timer
tmr.Interval = 500
AddHandler AList.Change, AddressOf OnCollectionChange
End Sub
#End Region
#Region "Properties"
Public Property ImageList() As ImageList
Get
Return Me.intImgLst
End Get
Set(ByVal Value As ImageList)
intImgLst = Value
If Not intParent Is Nothing Then
Me.intParent.Refresh()
End If
End Set
End Property
Public ReadOnly Property Buttons() As BVToolBarButtonCollection 'BVToolBarButtonCollectionExt
Get
Return AList
End Get
End Property
<Browsable(False)> _
Public Overrides Property Rectangle() As System.Drawing.Rectangle
Get
If Me.intVisible Then
Return Me.intRec
End If
Return New Rectangle(Me.Location, Me.Size)
End Get
Set(ByVal Value As System.Drawing.Rectangle)
Me.intRec = Value
Me.UpdateButtons()
End Set
End Property
<Browsable(False)> _
Public Overrides Property Location() As Point
Get
Return Me.intRec.Location
End Get
Set(ByVal Value As Point)
Me.intRec.Location = Value
Me.UpdateButtons()
End Set
End Property
<Browsable(False)> _
Public Shadows ReadOnly Property Size() As Size
Get
If Me.intVisible Then
Return Me.intRec.Size
End If
Return New Size(0, 0)
End Get
End Property
<Browsable(False)> _
Public ReadOnly Property Width() As Integer
Get
If Me.intVisible Then
Return Me.intRec.Width
End If
Return 0
End Get
End Property
<Browsable(False)> _
Public ReadOnly Property Height() As Integer
Get
If Me.intVisible Then
Return Me.intRec.Height
End If
Return 0
End Get
End Property
<Browsable(False)> _
Public Overrides Property Parent() As BVToolBar
Get
Return intParent
End Get
Set(ByVal Value As BVToolBar)
If intParent Is Value Then
Exit Property
End If
If Not intParent Is Nothing Then
If intParent Is Value Then
intParent.Bands.Remove(Me) 'un botton o banda solo tiene un parent Value
End If
End If
intParent = Value
tltipTxt.Parent = Me.intParent
Me.AList.Parent = Value
For Each btn As BVToolBarButton In Me.AList
btn.Parent = Value
Next
End Set
End Property
Public Property BorderStyle() As System.Windows.Forms.BorderStyle
Get
Return Me.intBorderStyle
End Get
Set(ByVal Value As System.Windows.Forms.BorderStyle)
intBorderStyle = Value
If Not intParent Is Nothing Then
Me.intParent.Refresh()
End If
End Set
End Property
#End Region
Protected Overridable Sub OnTimerTick(ByVal sender As Object, ByVal e As EventArgs) Handles tmr.Tick
tmr.Stop()
If MouseOver > -1 AndAlso MouseOver < AList.Count Then
tltipTxt.Location = New Point(AList(MouseOver).Location.X, AList(MouseOver).Location.Y + 30)
tltipTxt.Show()
End If
End Sub
#Region "Mouse Methods"
Protected Overridable Sub On_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles intParent.MouseMove
If Me.intVisible = False OrElse Not Me.intEnabled Then
Exit Sub
End If
Dim i As Integer
For i = 0 To AList.Count - 1
If Not AList(i).Style = ToolBarButtonStyle.Separator Then
If AList(i).Visible AndAlso AList(i).Enabled Then
If AList(i).Rectangle.Contains(e.X, e.Y) Then
If MouseOver <> i Then
tltipTxt.Hide()
MouseOver = i
If AList(MouseOver).ToolTipText <> "" Then
tltipTxt.Text = AList(MouseOver).ToolTipText
tmr.Start()
End If
intParent.Refresh()
End If
Exit Sub
End If
End If
End If
Next
tmr.Stop()
tltipTxt.Hide()
If MouseOver <> -1 Then
MouseOver = -1
intParent.Refresh()
End If
End Sub
Protected Overridable Sub On_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles intParent.MouseLeave
tmr.Stop()
tltipTxt.Hide()
If Me.intVisible = False Then
Exit Sub
End If
If MouseOver <> -1 Then
MouseOver = -1
Me.intParent.Refresh()
End If
End Sub
Protected Overridable Sub On_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles intParent.MouseDown
If Me.intVisible = False Then
Exit Sub
End If
Dim i As Integer
For i = 0 To AList.Count - 1
If AList(i).Enabled AndAlso AList(i).Visible Then
If AList(i).Rectangle.Contains(e.X, e.Y) Then
If AList(i).Style = ToolBarButtonStyle.ToggleButton Then
AList(i).Pushed = Not AList(i).Pushed
ElseIf AList(i).Style = ToolBarButtonStyle.DropDownButton Then
Dim r As Rectangle
r = AList(i).Rectangle
If Me.intParent.Dock = DockStyle.Bottom OrElse Me.intParent.Dock = DockStyle.Top Then
r.X += Me.intParent.ButtonSize.Width
r.Width -= Me.intParent.ButtonSize.Width
Else
r.Y += Me.intParent.ButtonSize.Height
r.Height -= Me.intParent.ButtonSize.Height
End If
If r.Contains(e.X, e.Y) AndAlso Not AList(i).DropDownMenu Is Nothing Then
If TypeOf AList(i).DropDownMenu Is ContextMenu Then
CType(AList(i).DropDownMenu, ContextMenu).Show(Me.intParent, New Point(AList(i).Rectangle.Right, AList(i).Rectangle.Bottom))
Else
'Dim cntMnu As ContextMenu
'Dim mnus() As MenuItem
'ReDim mnus(AList(i).DropDownMenu.MenuItems.Count - 1)
'AList(i).DropDownMenu.MenuItems.CopyTo(mnus, 0)
'cntMnu = New ContextMenu(mnus)
'cntMnu.Show(Me.intParent, AList(i).Location)
End If
Exit Sub
End If
End If
RaiseEvent ButtonClick(Me, New BVToolBarButtonClickEventArgs(AList(i)))
Exit Sub
End If
End If
Next
End Sub
#End Region
#Region "Local Methods"
Protected Sub UpdateButtons()
If Not intParent Is Nothing Then
Dim i, x As Integer
For i = 0 To AList.Count - 1
'dimension de los botones
If AList(i).Style = ToolBarButtonStyle.Separator Then
If intParent.Dock = DockStyle.Top Or intParent.Dock = DockStyle.Bottom Then
AList(i).Size = New Size(Me.intSeparatorDefaultLenght, Me.intParent.ButtonSize.Height)
ElseIf intParent.Dock = DockStyle.Left Or intParent.Dock = DockStyle.Right Then
AList(i).Size = New Size(Me.intParent.ButtonSize.Width, Me.intSeparatorDefaultLenght)
End If
ElseIf AList(i).Style = ToolBarButtonStyle.DropDownButton Then
If intParent.Dock = DockStyle.Top Or intParent.Dock = DockStyle.Bottom Then
AList(i).Size = New Size(Me.intParent.ButtonSize.Width + Me.intDropDownDefaultLenght, Me.intParent.ButtonSize.Height)
ElseIf intParent.Dock = DockStyle.Left Or intParent.Dock = DockStyle.Right Then
AList(i).Size = New Size(Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height + Me.intDropDownDefaultLenght)
End If
Else
AList(i).Size = New Size(Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height)
End If
'ubicacion de los botones
If intParent.Dock = DockStyle.Top Or intParent.Dock = DockStyle.Bottom Then
AList(i).Location = New Point(Me.intRec.Location.X + intTrackLenght + 1 + x, 2)
If AList(i).Visible Then
x += AList(i).Width '+ 1
End If
ElseIf intParent.Dock = DockStyle.Left Or intParent.Dock = DockStyle.Right Then
AList(i).Location = New Point(2, Me.intRec.Location.Y + intTrackLenght + 1 + x)
If AList(i).Visible Then
x += AList(i).Height '+ 1
End If
End If
Next
'dimension de la banda
If AList.Count = 0 Then
If intParent.Dock = DockStyle.Top Or intParent.Dock = DockStyle.Bottom Then
Me.intRec.Width = intTrackLenght
ElseIf intParent.Dock = DockStyle.Left Or intParent.Dock = DockStyle.Right Then
Me.intRec.Height = intTrackLenght
End If
Else
If intParent.Dock = DockStyle.Top Or intParent.Dock = DockStyle.Bottom Then
Me.intRec.Width = x + intTrackLenght + 5 '15 '+ AList.Count * Me.intParent.ButtonSize.Width
ElseIf intParent.Dock = DockStyle.Left Or intParent.Dock = DockStyle.Right Then
Me.intRec.Height = x + intTrackLenght + 5 ' 15 '+ AList.Count * Me.intParent.ButtonSize.Width
End If
End If
If intParent.Dock = DockStyle.Top Or intParent.Dock = DockStyle.Bottom Then
Me.intRec.Height = Me.intParent.ButtonSize.Height + 2
ElseIf intParent.Dock = DockStyle.Left Or intParent.Dock = DockStyle.Right Then
Me.intRec.Width = Me.intParent.ButtonSize.Width + 2
End If
Else
Me.intRec.Width = intTrackLenght
Me.intRec.Height = intTrackLenght
'If intParent.Dock = DockStyle.Top Or intParent.Dock = DockStyle.Bottom Then
'ElseIf intParent.Dock = DockStyle.Left Or intParent.Dock = DockStyle.Right Then
'End If
End If
End Sub
#End Region
Public Overrides Sub Redraw(ByVal sender As Object, ByVal P As PaintEventArgs)
If Not Me.intVisible Then
Exit Sub
End If
If intBorderStyle = BorderStyle.FixedSingle Then
ControlPaint.DrawBorder3D(P.Graphics, Me.Location.X, Me.Location.Y, Me.Width, Me.Height, Border3DStyle.Etched)
ElseIf intBorderStyle = BorderStyle.Fixed3D Then
ControlPaint.DrawBorder(P.Graphics, New Rectangle(Me.Location, Me.Size), ControlPaint.Dark(Me.intParent.BackColor), ButtonBorderStyle.Outset)
End If
Dim j, M, x, y As Integer
Dim intp As Pen
intp = New Pen(ControlPaint.Dark(Me.intParent.BackColor))
If Me.intParent.Dock = DockStyle.Top Or Me.intParent.Dock = DockStyle.Bottom Then
x = Location.X + 2
M = (Me.Height - 2) / 2
For j = 0 To M
y = Location.Y + 2 * j
P.Graphics.DrawLine(intp, x, y, x + Me.intTrackLenght - 6, y)
Next
ElseIf Me.intParent.Dock = DockStyle.Left Or Me.intParent.Dock = DockStyle.Right Then
y = Location.Y + 2
M = (Me.Width - 2) / 2
For j = 0 To M
x = Location.X + 2 * j
P.Graphics.DrawLine(intp, x, y, x, y + Me.intTrackLenght - 6)
Next
End If
Dim i As Integer
Dim imgLst As ImageList
For i = 0 To AList.Count - 1
If AList(i).Visible Then
x = AList(i).Location.X
y = AList(i).Location.Y
If AList(i).Style = ToolBarButtonStyle.Separator Then
If Me.intParent.Dock = DockStyle.Top Or Me.intParent.Dock = DockStyle.Bottom Then
P.Graphics.DrawLine(intp, x + 4, y + 1, x + 4, Me.Height - 4)
ElseIf Me.intParent.Dock = DockStyle.Left Or Me.intParent.Dock = DockStyle.Right Then
P.Graphics.DrawLine(intp, x + 1, y + 4, Me.Width - 1, y + 4)
End If
Else
If AList(i).Pushed AndAlso AList(i).Style = ToolBarButtonStyle.ToggleButton Then
ControlPaint.DrawButton(P.Graphics, New Rectangle(x, y, Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), ButtonState.Pushed)
ElseIf MouseOver = i Then
ControlPaint.DrawButton(P.Graphics, New Rectangle(x, y, Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), ButtonState.All)
End If
If Not Me.intImgLst Is Nothing Then
imgLst = Me.intImgLst
ElseIf Not Me.intParent.ImageList Is Nothing Then
imgLst = Me.intParent.ImageList
End If
If Not imgLst Is Nothing Then
If AList(i).Pushed _
AndAlso AList(i).Enabled _
AndAlso AList(i).Style = ToolBarButtonStyle.ToggleButton _
AndAlso AList(i).PushedImageIndex < imgLst.Images.Count _
AndAlso AList(i).PushedImageIndex > -1 Then
P.Graphics.DrawImage(imgLst.Images.Item(AList(i).PushedImageIndex), _
x + 2, _
y + 2, _
Me.intParent.ButtonSize.Width - 4, _
Me.intParent.ButtonSize.Height - 4)
Else
If Not AList(i).Enabled Then
Dim img As Image
img = New Bitmap(imgLst.Images.Item(AList(i).ImageIndex), Me.intParent.ButtonSize.Width - 4, _
Me.intParent.ButtonSize.Height - 4)
ControlPaint.DrawImageDisabled(P.Graphics, img, x + 2, y + 2, Color.Gray)
'ControlPaint.DrawImageDisabled
'ControlPaint.DrawButton(P.Graphics, _
' New Rectangle( _
' x + 2, _
' y + 2, _
' Me.intParent.ButtonSize.Width - 4, _
' Me.intParent.ButtonSize.Height - 4), _
' ButtonState.Flat)
ElseIf AList(i).ImageIndex < imgLst.Images.Count AndAlso AList(i).ImageIndex > -1 Then
P.Graphics.DrawImage(imgLst.Images.Item(AList(i).ImageIndex), _
x + 2, _
y + 2, _
Me.intParent.ButtonSize.Width - 4, _
Me.intParent.ButtonSize.Height - 4)
End If
End If
End If
If AList(i).Style = ToolBarButtonStyle.DropDownButton Then
'ControlPaint.DrawButton(P.Graphics, New Rectangle(x + Me.intParent.ButtonSize.Width, y, AList(i).Width - Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), ButtonState.Flat)
ControlPaint.DrawComboButton(P.Graphics, New Rectangle(x + Me.intParent.ButtonSize.Width, y, AList(i).Width - Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), ButtonState.Flat)
'ControlPaint.DrawCombButton(P.Graphics, New Rectangle(x + Me.intParent.ButtonSize.Width, y, AList(i).Width - Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), ButtonState.Flat)
'ControlPaint.DrawMenuGlyph(P.Graphics, New Rectangle(x + Me.intParent.ButtonSize.Width, y, AList(i).Width - Me.intParent.ButtonSize.Width, Me.intParent.ButtonSize.Height), MenuGlyph.Arrow)
End If
End If
End If
Next
End Sub
#Region "Events Capture Methods"
Protected Sub OnCollectionChange(ByVal sender As Object, ByVal e As EventArgs)
Me.UpdateButtons()
RaiseEvent Change(Me, New EventArgs)
End Sub
Protected Sub OnChange(ByVal sender As Object, ByVal e As EventArgs)
RaiseEvent Change(sender, e)
End Sub
#End Region
End Class