Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
'ControlPaint.DrawGrabHandle(p.Graphics, New Rectangle(1, intRect.Y, 20, 20), True, True)
'ControlPaint.DrawContainerGrabHandle(p.Graphics, New Rectangle(1, intRect.Y, 15, 15))
'ControlPaint.DrawMenuGlyph(p.Graphics, New Rectangle(1, intRect.Y, 15, 15), MenuGlyph.Min)
', ToolboxBitmap(GetType(BVToolBar), "BVToolBar.ico")
<DefaultEvent("ButtonClick"), _
DefaultProperty("Bands"), _
DesignerAttribute(GetType(BVToolBarDesigner)), _
CLSCompliant(True)> _
Public Class BVToolBar
Inherits System.Windows.Forms.UserControl
#Region " C�digo generado por el Dise�ador de Windows Forms "
Public Sub New()
MyBase.New()
'El Dise�ador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicializaci�n despu�s de la llamada a InitializeComponent()
Me.Initialize()
End Sub
'UserControl reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Dise�ador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Dise�ador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Dise�ador de Windows Forms.
'No lo modifique con el editor de c�digo.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'UserControl1
'
Me.Name = "UserControl1"
Me.Size = New System.Drawing.Size(448, 48)
End Sub
#End Region
Protected intMaxButtonLenght As Integer = 60 'maxima dimension por defecto del boton estandar
Protected intBrush As SolidBrush
Protected WithEvents AList As BVToolBarBandCollection 'BVArrayList
Protected imgLst As ImageList
'Private intMustRefresh As Boolean
Private intAutoSize As Boolean
Private intAppearance As System.Windows.Forms.ToolBarAppearance
Private intButtonSize As System.Drawing.Size
Private intDivider As Boolean
Private intBorderStyle As System.Windows.Forms.BorderStyle
Protected intThumbSize As Size
Public Event ButtonClick(ByVal sender As Object, ByVal e As BVToolBarButtonClickEventArgs)
Public Event ButtonDropDown(ByVal sender As Object, ByVal e As BVToolBarButtonClickEventArgs)
#Region "Initialize"
Protected Overridable Sub Initialize()
AList = New BVToolBarBandCollection(Me)
imgLst = New ImageList
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.UserPaint, True)
BackColor = Color.White
intBrush = New System.Drawing.SolidBrush(BackColor)
Me.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right
MyBase.Dock = DockStyle.Top
End Sub
Private Sub BVToolBar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
intButtonSize = New Size(32, 32)
Me.Height = intButtonSize.Height
Me.Location = New Point(0, 0)
'MyBase.Dock = Me.Dock
If Not Me.Parent Is Nothing Then
Me.Width = Me.Parent.Width
Me.BackColor = Me.Parent.BackColor
End If
Me.UpdateBands()
End Sub
#End Region
#Region "Properties"
Public ReadOnly Property Bands() As BVToolBarBandCollection 'BVToolBarBandCollectionExt
Get
Return AList
End Get
End Property
Public Property ImageList() As ImageList
Get
Return Me.imgLst
End Get
Set(ByVal Value As ImageList)
imgLst = Value
Me.Refresh()
End Set
End Property
Public Property Appearance() As System.Windows.Forms.ToolBarAppearance
Get
Return intAppearance
End Get
Set(ByVal Value As System.Windows.Forms.ToolBarAppearance)
intAppearance = Value
MyBase.Refresh()
End Set
End Property
Public Overrides Property AutoSize() As Boolean
Get
Return Me.intAutoSize
End Get
Set(ByVal Value As Boolean)
intAutoSize = Value
End Set
End Property
Public Property ButtonSize() As System.Drawing.Size
Get
Return intButtonSize
End Get
Set(ByVal Value As System.Drawing.Size)
If Value.Width <= Me.intMaxButtonLenght AndAlso Value.Height <= Me.intMaxButtonLenght Then
intButtonSize = Value
OnResize(New EventArgs)
Me.UpdateBands()
MyBase.Refresh()
End If
End Set
End Property
Public Property Divider() As Boolean
Get
Return Me.intDivider
End Get
Set(ByVal Value As Boolean)
intDivider = Value
MyBase.Refresh()
End Set
End Property
Public Overloads Property BorderStyle() As System.Windows.Forms.BorderStyle
Get
Return Me.intBorderStyle
End Get
Set(ByVal Value As System.Windows.Forms.BorderStyle)
intBorderStyle = Value
MyBase.Refresh()
End Set
End Property
Public Overrides Property Dock() As DockStyle
Get
Return MyBase.Dock()
End Get
Set(ByVal Value As DockStyle)
Static IsRunning As Boolean
If IsRunning Then
Exit Property
End If
IsRunning = True
If MyBase.Dock <> Value AndAlso Value <> DockStyle.Fill AndAlso Value <> DockStyle.None Then
If Value = DockStyle.Top Then
Me.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Right
ElseIf Value = DockStyle.Left Then
Me.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Bottom
ElseIf Value = DockStyle.Right Then
Me.Anchor = AnchorStyles.Top Or AnchorStyles.Right Or AnchorStyles.Bottom
ElseIf Value = DockStyle.Bottom Then
Me.Anchor = AnchorStyles.Right Or AnchorStyles.Left Or AnchorStyles.Bottom
End If
MyBase.Dock = Value
OnResize(New EventArgs)
UpdateBands()
End If
IsRunning = False
End Set
End Property
#End Region
#Region "Capture Events Methods"
Protected Overrides Sub OnResize(ByVal e As EventArgs) 'Handles MyBase.Resize
Static IsProcessing As Boolean
If IsProcessing Then
Exit Sub
End If
IsProcessing = True
If Not Me.Parent Is Nothing Then
If MyBase.Dock = DockStyle.Top Or MyBase.Dock = DockStyle.Bottom Then
'Me.Height = Me.Width
Me.Height = Me.intButtonSize.Height + 4
Me.Width = Me.Parent.Width
If MyBase.Dock = DockStyle.Top Then
Me.Location = New Point(0, 0)
Else
If TypeOf Me.Parent Is Form Then
'Me.Height = CType(Me.Parent, Form).ClientSize.Height
Me.Location = New Point(0, CType(Me.Parent, Form).ClientSize.Height - Me.Height - 1)
Else
Me.Location = New Point(0, Me.Parent.Height - Me.Height - 1)
End If
End If
ElseIf MyBase.Dock = DockStyle.Left Or MyBase.Dock = DockStyle.Right Then
Me.Width = Me.intButtonSize.Width + 4
'Me.Width = Me.Height
If TypeOf Me.Parent Is Form Then
Me.Height = CType(Me.Parent, Form).ClientSize.Height
Else
Me.Height = Me.Parent.Height
End If
If MyBase.Dock = DockStyle.Left Then
Me.Location = New Point(0, 0)
Else
Me.Location = New Point(Me.Parent.Width - Me.Width - 7, 0)
End If
End If
End If
If Me.intAutoSize Then
'el ancho o alto se ajustan a los botones
If MyBase.Dock = DockStyle.Top Or MyBase.Dock = DockStyle.Bottom Then
Me.Height = Me.intButtonSize.Height + 4
ElseIf MyBase.Dock = DockStyle.Left Or MyBase.Dock = DockStyle.Right Then
Me.Width = Me.intButtonSize.Width + 4
End If
'Else
' 'los botones se ajustan al ancho o alto
' If MyBase.Dock = DockStyle.Top Or MyBase.Dock = DockStyle.Bottom Then
' Me.intButtonSize.Height = Me.Height - 4
' Me.intButtonSize.Width = Me.intButtonSize.Height
' ElseIf MyBase.Dock = DockStyle.Left Or MyBase.Dock = DockStyle.Right Then
' Me.intButtonSize.Width = Me.Width - 4
' Me.intButtonSize.Height = Me.intButtonSize.Width
' End If
End If
IsProcessing = False
End Sub
Protected Sub OnCollectionChange(ByVal sender As Object, ByVal e As EventArgs) Handles AList.Change
UpdateBands()
End Sub
Protected Sub OnButtonClick(ByVal sender As Object, ByVal e As BVToolBarButtonClickEventArgs) Handles AList.ButtonClick
'AList.e
RaiseEvent ButtonClick(sender, e)
End Sub
'Private Sub ToolBarMain_ButtonClick(ByVal sender As Object, ByVal e As BVToolBarButtonClickEventArgs) ' Handles TlBar.ButtonClick
' 'AList.Item(.Buttons.Execute(e.Button)
'End Sub
#End Region
Protected Sub UpdateBands()
Dim i As Integer
Dim x, y As Integer
For i = 0 To AList.Count - 1
If i = 0 Then
x = 1
y = 1
Else
If AList(i - 1).Visible Then
If MyBase.Dock = DockStyle.Top Or MyBase.Dock = DockStyle.Bottom Then
x = AList(i - 1).Location.X + AList(i - 1).Width
ElseIf MyBase.Dock = DockStyle.Left Or MyBase.Dock = DockStyle.Right Then
y = AList(i - 1).Location.Y + AList(i - 1).Height
End If
End If
End If
AList(i).Location = New Point(x, y)
Next
End Sub
Protected Overridable Sub Redraw(ByVal sender As Object, ByVal P As PaintEventArgs) Handles MyBase.Paint
Dim i As Integer
If intBorderStyle = BorderStyle.FixedSingle Then
ControlPaint.DrawBorder3D(P.Graphics, Me.Location.X + 1, Me.Location.Y + 1, Me.Width - 2, Me.Height - 1, Border3DStyle.RaisedOuter)
ElseIf intBorderStyle = BorderStyle.Fixed3D Then
ControlPaint.DrawBorder(P.Graphics, New Rectangle(Me.Location.X + 1, Me.Location.Y + 1, Me.Width - 2, Me.Height - 1), ControlPaint.Dark(Me.BackColor), ButtonBorderStyle.Outset)
End If
For i = 0 To AList.Count - 1
CType(AList(i), BVToolBarBand).Redraw(sender, P)
Next
End Sub
End Class