Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' /* *\
- ' |#* Elektro ListView *#|
- ' \* */
- '
- ' // By Elektro H@cker
- '
- ' -----------
- ' Properties:
- ' -----------
- '
- ' Double_Buffer
- ' Disable_Flickering
- ' ----------------
- ' UndoRedo_Enabled
- ' ----------------
- ' UseDefaultGridLines
- ' GridLineColor
- ' ----------------------
- ' ColumnHeader_Backcolor
- ' ColumnHeader_ForeColor
- ' ColumnHeader_Separator_Color
- ' ----------------------------
- ' ItemHighlightColor
- ' ItemNotFocusedHighlighColor
- ' ---------------------------
- ' ProgressBar_Enabled
- ' Progressbar_Column
- ' ProgressBar_BackColor
- ' ProgressBar_BorderColor
- ' ProgressBar_FillColor1
- ' ProgressBar_FillColor2
- ' ProgressPercent
- ' ProgressPercent_Decimal
- ' ProgressPercent_Text
- ' ProgressPercent_Text_Allignment
- ' ProgressPercent_Text_Trimming
- ' ProgressPercent_Font
- ' ProgressPercent_Forecolor
- '
- ' -------
- ' Events:
- ' -------
- '
- ' ItemAdded
- ' ItemRemoved
- ' UndoRedo_IsPerformed
- ' UndoRedo_StackSizeChanged
- '
- ' --------
- ' Methods:
- ' --------
- ' AddItem
- ' AddItems
- ' RemoveItem
- ' RemoveItems
- ' Undo
- ' Redo
- Public Class ElektroListView : Inherits ListView
- #Region " Members "
- #Region " Variables "
- ''' <summary>
- ''' Tries to avoid any flickering effect on this ListView.
- ''' </summary>
- Private _Disable_Flickering As Boolean = True
- #End Region
- #Region " Properties "
- ''' <summary>
- ''' Set the Double Buffer.
- ''' </summary>
- Public Property Double_Buffer() As Boolean
- Get
- Return Me.DoubleBuffered
- End Get
- Set(ByVal Value As Boolean)
- Me.DoubleBuffered = Value
- End Set
- End Property
- ''' <summary>
- ''' Tries to avoid any flickering effect on this ListView.
- '''
- ''' This property turns off any Flicker effect on the ListView
- ''' ...but also reduces the performance (speed) of the ListView about 30% slower.
- ''' This don't affect to the performance of the application itself, only to the performance of this control.
- ''' </summary>
- Public Property Disable_Flickering() As Boolean
- Get
- Return _Disable_Flickering
- End Get
- Set(ByVal Value As Boolean)
- Me._Disable_Flickering = Value
- End Set
- End Property
- ''' <summary>
- ''' Enable/Disable any flickering effect on the ListView.
- ''' </summary>
- Protected Overrides ReadOnly Property CreateParams() As CreateParams
- Get
- If _Disable_Flickering Then
- Dim cp As CreateParams = MyBase.CreateParams
- cp.ExStyle = cp.ExStyle Or &H2000000
- Return cp
- Else
- Return MyBase.CreateParams
- End If
- End Get
- End Property
- #End Region
- #Region " Events "
- ''' <summary>
- ''' Event is raised when an Item is added into the ListView.
- ''' </summary>
- Public Event ItemAdded As EventHandler(Of ItemAddedEventArgs)
- Public Class ItemAddedEventArgs : Inherits EventArgs
- Public Property Item As ListViewItem
- End Class
- ''' <summary>
- ''' Event is raised when an Item is removed from the ListView.
- ''' </summary>
- Public Event ItemRemoved As EventHandler(Of ItemRemovedEventArgs)
- Public Class ItemRemovedEventArgs : Inherits EventArgs
- Public Property Item As ListViewItem
- End Class
- #End Region
- #End Region
- #Region " Constructor "
- Public Sub New()
- Me.Name = "ElektroListView"
- Me.DoubleBuffered = True
- Me.UseDefaultGridLines = True
- Me.GridLines = True
- Me.FullRowSelect = True
- Me.MultiSelect = True
- Me.View = View.Details
- ' Set Listview OwnerDraw to True, so we can draw the items and/or the progressbar inside.
- Me.OwnerDraw = True
- End Sub
- #End Region
- #Region " Public Methods "
- ''' <summary>
- ''' Adds an Item to the ListView,
- ''' to monitor when an Item is added to the ListView.
- ''' </summary>
- Public Function AddItem(ByVal Item As ListViewItem) As ListViewItem
- Me.Items.Add(Item)
- RaiseEvent ItemAdded(Me, New ItemAddedEventArgs With {.Item = Item})
- Return Item
- End Function
- ''' <summary>
- ''' Adds an Item to the ListView,
- ''' to monitor when an Item is added to the ListView.
- ''' </summary>
- Public Function AddItem(ByVal Text As String) As ListViewItem
- Dim NewItem As New ListViewItem(Text)
- Me.Items.Add(NewItem)
- RaiseEvent ItemAdded(Me, New ItemAddedEventArgs With {.Item = NewItem})
- Return NewItem
- End Function
- ''' <summary>
- ''' Removes an Item from the ListView
- ''' to monitor when an Item is removed from the ListView.
- ''' </summary>
- Public Sub RemoveItem(ByVal Item As ListViewItem)
- Me.Items.Remove(Item)
- RaiseEvent ItemRemoved(Me, New ItemRemovedEventArgs With {.Item = Item})
- End Sub
- ''' <summary>
- ''' Removes an Item from the ListView at given Index
- ''' to monitor when an Item is removed from the ListView.
- ''' </summary>
- Public Sub RemoveItem_At(ByVal Index As Integer)
- RemoveItem(Me.Items.Item(Index))
- End Sub
- ''' <summary>
- ''' Removes an Item from the ListView at given Index
- ''' to monitor when an Item is removed from the ListView.
- ''' </summary>
- Public Sub RemoveItems_At(ByVal Indexes As Integer())
- Array.Sort(Indexes)
- Array.Reverse(Indexes)
- For Each Index As Integer In Indexes
- RemoveItem(Me.Items.Item(Index))
- Next
- End Sub
- ''' <summary>
- ''' Adds a range of Items to the ListView,
- ''' to monitor when an Item is added to the ListView.
- ''' </summary>
- Public Sub AddItems(ByVal Items As ListViewItem())
- For Each item As ListViewItem In Items
- AddItem(item)
- Next
- End Sub
- ''' <summary>
- ''' Adds a range of Items to the ListView,
- ''' to monitor when an Item is added to the ListView.
- ''' </summary>
- Public Sub AddItems(ByVal Items As ListViewItemCollection)
- For Each item As ListViewItem In Items
- AddItem(item)
- Next
- End Sub
- ''' <summary>
- ''' Removes a range of Items from the ListView
- ''' to monitor when an Item is removed from the ListView.
- ''' </summary>
- Public Sub RemoveItems(ByVal Items As ListViewItem())
- For Each item As ListViewItem In Items
- RemoveItem(item)
- Next
- End Sub
- ''' <summary>
- ''' Removes a range of Items from the ListView
- ''' to monitor when an Item is removed from the ListView.
- ''' </summary>
- Public Sub RemoveItems(ByVal Items As ListViewItemCollection)
- For Each item As ListViewItem In Items
- RemoveItem(item)
- Next
- End Sub
- ''' <summary>
- ''' Removes a range of Items from the ListView
- ''' to monitor when an Item is removed from the ListView.
- ''' </summary>
- Public Sub RemoveItems(ByVal Items As SelectedListViewItemCollection)
- For Each item As ListViewItem In Items
- RemoveItem(item)
- Next
- End Sub
- #End Region
- #Region " Features "
- #Region " Column/Item/Grid Paintings "
- #Region " Members "
- #Region " Variables "
- ''' <summary>
- ''' Indicates the Backcolor of the Column headers.
- ''' </summary>
- Private _columnheader_backcolor As SolidBrush = New SolidBrush(Color.FromArgb(51, 50, 49))
- ''' <summary>
- ''' Indicates the ForeColor of the Column headers.
- ''' </summary>
- Private _columnheader_forecolor As SolidBrush = New SolidBrush(Color.Silver)
- ''' <summary>
- ''' Indicates the ForeColor of the Column headers separators.
- ''' </summary>
- Private _columnheader_separator_color As Pen = SystemPens.ControlLightLight
- ''' <summary>
- ''' Indicates the color to use to highlight the items.
- ''' </summary>
- Private _itemHighlightColor As Color = Color.FromKnownColor(KnownColor.Highlight)
- ''' <summary>
- ''' Indicates the color to use when the item is not focused.
- ''' </summary>
- Private _itemNotFocusedHighlighColor As Color = Color.FromKnownColor(KnownColor.MenuBar)
- ''' <summary>
- ''' Indicates whether the ListView should use GridLines.
- ''' </summary>
- Private _gridLines As Boolean = False
- ''' <summary>
- ''' Indicates whether the ListView should draw default gridlines.
- ''' </summary>
- Private _useDefaultGridLines As Boolean = False
- ''' <summary>
- ''' Indicates the GridLines color.
- ''' </summary>
- Private _gridLineColor As Color = Color.Black
- #End Region
- #Region " Properties "
- ''' <summary>
- ''' Indicates the Backcolor of the Column headers.
- ''' </summary>
- Public Property ColumnHeader_Backcolor As Color
- Get
- Return _columnheader_backcolor.Color
- End Get
- Set(ByVal value As Color)
- If Not _columnheader_backcolor.Color = value Then
- _columnheader_backcolor = New SolidBrush(value)
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ForeColor of the Column headers.
- ''' </summary>
- Public Property ColumnHeader_ForeColor As Color
- Get
- Return _columnheader_forecolor.Color
- End Get
- Set(ByVal value As Color)
- If Not _columnheader_forecolor.Color = value Then
- _columnheader_forecolor = New SolidBrush(value)
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ForeColor of the Column headers separators.
- ''' </summary>
- Public Property ColumnHeader_Separator_Color As Color
- Get
- Return _columnheader_separator_color.Color
- End Get
- Set(ByVal value As Color)
- If Not _columnheader_separator_color.Color = value Then
- _columnheader_separator_color = New Pen(value)
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the color to use to highlight the items.
- ''' </summary>
- Public Property ItemHighlightColor() As Color
- Get
- Return _itemHighlightColor
- End Get
- Set(ByVal value As Color)
- If Not _itemHighlightColor = value Then
- _itemHighlightColor = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the color to use when the item is not focused.
- ''' </summary>
- Public Property ItemNotFocusedHighlighColor() As Color
- Get
- Return _itemNotFocusedHighlighColor
- End Get
- Set(ByVal value As Color)
- If Not _itemNotFocusedHighlighColor = value Then
- _itemNotFocusedHighlighColor = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates whether the ListView should use GridLines.
- ''' </summary>
- Public Shadows Property GridLines() As Boolean
- Get
- Return _gridLines
- End Get
- Set(ByVal value As Boolean)
- _gridLines = value
- End Set
- End Property
- ''' <summary>
- ''' Indicates whether the ListView should draw default gridlines.
- ''' </summary>
- Public Property UseDefaultGridLines() As Boolean
- Get
- Return _useDefaultGridLines
- End Get
- Set(ByVal value As Boolean)
- If Not _useDefaultGridLines = value Then
- _useDefaultGridLines = value
- Me.Invalidate(False)
- End If
- MyBase.GridLines = value
- End Set
- End Property
- ''' <summary>
- ''' Indicates the GridLines color.
- ''' </summary>
- Public Property GridLineColor() As Color
- Get
- Return _gridLineColor
- End Get
- Set(ByVal value As Color)
- If Not _gridLineColor = value Then
- _gridLineColor = value
- If _gridLines Then
- Me.Invalidate(False)
- End If
- End If
- End Set
- End Property
- #End Region
- #End Region
- #Region " Event Handlers "
- ' Me [DrawColumnHeader]
- Public Sub Me_DrawColumnHeader(ByVal sender As Object, ByVal e As DrawListViewColumnHeaderEventArgs) _
- Handles Me.DrawColumnHeader
- e.DrawDefault = False ' Set ownerdraw.
- 'BACKGROUND
- Using brush As Brush = New SolidBrush(Me.ColumnHeader_Backcolor)
- e.Graphics.FillRectangle(brush, e.Bounds)
- End Using
- Dim bounds As Rectangle = e.Bounds
- bounds.Width -= 1
- bounds.Height -= 1
- e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, bounds)
- ' bounds.Width -= 1
- ' bounds.Height -= 1
- 'e.Graphics.DrawLine(SystemPens.ControlLightLight, bounds.X, bounds.Y, bounds.Right, bounds.Y)
- 'e.Graphics.DrawLine(SystemPens.ControlLightLight, bounds.X, bounds.Y, bounds.X, bounds.Bottom)
- ' e.Graphics.DrawLine(SystemPens.ControlDark, (bounds.X + 1), bounds.Bottom, bounds.Right, bounds.Bottom)
- e.Graphics.DrawLine(_columnheader_separator_color, bounds.Right, (bounds.Y), bounds.Right, bounds.Bottom)
- 'TEXT
- Dim textAlign As HorizontalAlignment = e.Header.TextAlign
- Dim flags As TextFormatFlags = If((textAlign = HorizontalAlignment.Left), TextFormatFlags.GlyphOverhangPadding, If((textAlign = HorizontalAlignment.Center), TextFormatFlags.HorizontalCenter, TextFormatFlags.Right))
- flags = (flags Or TextFormatFlags.VerticalCenter)
- Dim text As String = e.Header.Text
- Dim width As Integer = TextRenderer.MeasureText(" ", e.Font).Width - 8
- bounds = Rectangle.Inflate(e.Bounds, -width, 0)
- TextRenderer.DrawText(e.Graphics, [text], e.Font, bounds, Me.ColumnHeader_ForeColor, flags)
- End Sub
- ' Me [DrawItem]
- Public Sub Me_DrawItem(ByVal sender As Object, ByVal e As DrawListViewItemEventArgs) _
- Handles Me.DrawItem
- e.DrawDefault = False ' Set OwnerDraw.
- End Sub
- Protected Overrides Sub OnDrawColumnHeader(ByVal e As DrawListViewColumnHeaderEventArgs)
- e.DrawDefault = True
- MyBase.OnDrawColumnHeader(e)
- End Sub
- Protected Overrides Sub OnLostFocus(ByVal e As EventArgs)
- For Each selectedIndex As Integer In MyBase.SelectedIndices
- MyBase.RedrawItems(selectedIndex, selectedIndex, False)
- Next
- MyBase.OnLostFocus(e)
- End Sub
- Protected Overrides Sub OnDrawSubItem(ByVal e As DrawListViewSubItemEventArgs)
- Dim drawAsDefault As Boolean = False
- Dim highlightBounds As Rectangle = Nothing
- Dim highlightBrush As SolidBrush = Nothing
- 'FIRST DETERMINE THE COLOR
- If e.Item.Selected Then
- If MyBase.Focused Then
- highlightBrush = New SolidBrush(_itemHighlightColor)
- ElseIf HideSelection Then
- drawAsDefault = True
- Else
- highlightBrush = New SolidBrush(_itemNotFocusedHighlighColor)
- End If
- Else
- drawAsDefault = True
- End If
- If drawAsDefault Then
- e.DrawBackground()
- Else
- 'NEXT DETERMINE THE BOUNDS IN WHICH TO DRAW THE BACKGROUND
- If FullRowSelect Then
- highlightBounds = e.Bounds
- Else
- highlightBounds = e.Item.GetBounds(ItemBoundsPortion.Label)
- End If
- 'ONLY DRAW HIGHLIGHT IN 1 OF 2 CASES
- 'CASE 1 - FULL ROW SELECT (AND DRAWING ANY ITEM)
- 'CASE 2 - NOT FULL ROW SELECT (AND DRAWING 1ST ITEM)
- If FullRowSelect Then
- e.Graphics.FillRectangle(highlightBrush, highlightBounds)
- ElseIf e.ColumnIndex = 0 Then
- e.Graphics.FillRectangle(highlightBrush, highlightBounds)
- Else
- e.DrawBackground()
- End If
- End If
- Dim bounds As Rectangle = e.Bounds
- bounds.X += 5
- bounds.Width -= 5
- Select Case e.Header.TextAlign
- Case HorizontalAlignment.Left
- TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font,
- bounds, e.SubItem.ForeColor,
- TextFormatFlags.Left Or _
- TextFormatFlags.EndEllipsis)
- Case HorizontalAlignment.Center
- TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font,
- bounds, e.SubItem.ForeColor,
- TextFormatFlags.GlyphOverhangPadding Or _
- TextFormatFlags.HorizontalCenter Or _
- TextFormatFlags.EndEllipsis)
- Case HorizontalAlignment.Right
- TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font,
- bounds, e.SubItem.ForeColor,
- TextFormatFlags.Right Or _
- TextFormatFlags.EndEllipsis)
- End Select
- If _gridLines Then
- e.Graphics.DrawRectangle(New Pen(_gridLineColor), e.Bounds)
- End If
- If FullRowSelect Then
- e.DrawFocusRectangle(e.Item.GetBounds(ItemBoundsPortion.Entire))
- Else
- e.DrawFocusRectangle(e.Item.GetBounds(ItemBoundsPortion.Label))
- End If
- MyBase.OnDrawSubItem(e)
- End Sub
- #End Region
- #End Region
- #Region " ProgressBar "
- #Region " Members "
- #Region " Variables "
- ''' <summary>
- ''' Enable or disable the drawing of the ProgressBar.
- ''' This property should be "True" to use any of the ProgressBar features.
- ''' </summary>
- Private _ProgressBar_Enabled As Boolean = False
- ''' <summary>
- ''' Indicates the column index to draw the ProgressBar.
- ''' </summary>
- Private _Progressbar_Column As Integer = Nothing
- ''' <summary>
- ''' Indicates the ProgressBar BackColor.
- ''' </summary>
- Private _ProgressBar_BackColor As SolidBrush = New SolidBrush(Color.Red)
- ''' <summary>
- ''' The ProgressBar BorderColor.
- ''' </summary>
- Private _ProgressBar_BorderColor As Pen = New Pen(Color.LightGray)
- ''' <summary>
- ''' Indicates the first ProgressBar gradient color.
- ''' </summary>
- Private _ProgressBar_FillColor1 As Color = Color.YellowGreen
- ''' <summary>
- ''' Indicates the last ProgressBar gradient color.
- ''' </summary>
- Private _ProgressBar_FillColor2 As Color = Color.White
- ''' <summary>
- ''' Indicates the ProgressBar Percent value.
- ''' </summary>
- Private _ProgressPercent As Double = 0
- ''' <summary>
- ''' Indicates the ProgressBar Percent Value decimal factor.
- ''' </summary>
- Private _ProgressPercent_Decimal As Short = 2
- ''' <summary>
- ''' Indicates the ProgressBar Percent text.
- ''' </summary>
- Private _ProgressPercent_Text As String = "%"
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text Allignment.
- ''' </summary>
- Private _ProgressPercent_Text_Allignment As StringAlignment = StringAlignment.Center
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text Trimming.
- ''' </summary>
- Private _ProgressPercent_Text_Trimming As StringTrimming = StringTrimming.EllipsisCharacter
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text StringFormat.
- ''' </summary>
- Private _ProgressPercent_StringFormat As StringFormat = New StringFormat With
- {
- .Alignment = _ProgressPercent_Text_Allignment,
- .Trimming = _ProgressPercent_Text_Trimming
- }
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text Font.
- ''' </summary>
- Private _ProgressPercent_Font As Font = Me.Font
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text ForeColor.
- ''' </summary>
- Private _ProgressPercent_ForeColor As SolidBrush = New SolidBrush(Color.Black)
- #End Region
- #Region " Properties "
- ''' <summary>
- ''' Enable or disable the drawing of the ProgressBar.
- ''' This property should be "True" to use any of the ProgressBar features.
- ''' </summary>
- Public Property ProgressBar_Enabled As Boolean
- Get
- Return _ProgressBar_Enabled
- End Get
- Set(ByVal value As Boolean)
- If Not _ProgressBar_Enabled = value Then
- _ProgressBar_Enabled = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the column index to draw the ProgressBar.
- ''' </summary>
- Public Property Progressbar_Column As Integer
- Get
- Return _Progressbar_Column
- End Get
- Set(ByVal value As Integer)
- If Not _Progressbar_Column = value Then
- _Progressbar_Column = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ProgressBar BackColor.
- ''' </summary>
- Public Property ProgressBar_BackColor As Color
- Get
- Return _ProgressBar_BackColor.Color
- End Get
- Set(ByVal value As Color)
- If Not _ProgressBar_BackColor.Color = value Then
- _ProgressBar_BackColor = New SolidBrush(value)
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' The ProgressBar BorderColor.
- ''' </summary>
- Public Property ProgressBar_BorderColor As Color
- Get
- Return _ProgressBar_BorderColor.Color
- End Get
- Set(ByVal value As Color)
- If Not _ProgressBar_BorderColor.Color = value Then
- _ProgressBar_BorderColor = New Pen(value)
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the first ProgressBar gradient color.
- ''' </summary>
- Public Property ProgressBar_FillColor1 As Color
- Get
- Return _ProgressBar_FillColor1
- End Get
- Set(ByVal value As Color)
- If Not _ProgressBar_FillColor1 = value Then
- _ProgressBar_FillColor1 = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the last ProgressBar gradient color.
- ''' </summary>
- Public Property ProgressBar_FillColor2 As Color
- Get
- Return _ProgressBar_FillColor2
- End Get
- Set(ByVal value As Color)
- If Not _ProgressBar_FillColor2 = value Then
- _ProgressBar_FillColor2 = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the current ProgressBar Percent value.
- ''' </summary>
- Public Property ProgressPercent As Double
- Get
- Return _ProgressPercent
- End Get
- Set(ByVal value As Double)
- If Not _ProgressPercent = value Then
- _ProgressPercent = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ProgressBar Percent Value decimal factor.
- ''' </summary>
- Public Property ProgressPercent_Decimal As Short
- Get
- Return _ProgressPercent_Decimal
- End Get
- Set(ByVal value As Short)
- If Not _ProgressPercent_Decimal = value Then
- _ProgressPercent_Decimal = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ProgressBar Percent text.
- ''' </summary>
- Public Property ProgressPercent_Text As String
- Get
- Return _ProgressPercent_Text
- End Get
- Set(ByVal value As String)
- If Not _ProgressPercent_Text = value Then
- _ProgressPercent_Text = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text Allignment.
- ''' </summary>
- Public Property ProgressPercent_Text_Allignment As StringAlignment
- Get
- Return _ProgressPercent_Text_Allignment
- End Get
- Set(ByVal value As StringAlignment)
- If Not _ProgressPercent_StringFormat.Alignment = value Then
- _ProgressPercent_StringFormat.Alignment = value
- _ProgressPercent_Text_Allignment = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text Trimming.
- ''' </summary>
- Public Property ProgressPercent_Text_Trimming As StringTrimming
- Get
- Return _ProgressPercent_Text_Trimming
- End Get
- Set(ByVal value As StringTrimming)
- If Not _ProgressPercent_StringFormat.Trimming = value Then
- _ProgressPercent_StringFormat.Trimming = value
- _ProgressPercent_Text_Trimming = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text Font.
- ''' </summary>
- Public Property ProgressPercent_Font As Font
- Get
- Return _ProgressPercent_Font
- End Get
- Set(ByVal value As Font)
- If Not _ProgressPercent_Font.Equals(value) Then
- _ProgressPercent_Font = value
- Me.Invalidate(False)
- End If
- End Set
- End Property
- ''' <summary>
- ''' Indicates the ProgressBar Percent Text ForeColor.
- ''' </summary>
- Public Property ProgressPercent_Forecolor As Color
- Get
- Return _ProgressPercent_ForeColor.Color
- End Get
- Set(ByVal value As Color)
- If Not _ProgressPercent_ForeColor.Color = value Then
- _ProgressPercent_ForeColor = New SolidBrush(value)
- Me.Invalidate(False)
- End If
- End Set
- End Property
- #End Region
- #End Region
- #Region " Event Handlers "
- ' ListView [DrawSubItem]
- Public Sub Me_DrawSubItem(ByVal sender As Object, ByVal e As DrawListViewSubItemEventArgs) _
- Handles Me.DrawSubItem
- If Not ProgressBar_Enabled OrElse Progressbar_Column = Nothing Then
- Exit Sub
- End If
- ' Item is highlighted.
- 'If (e.ItemState And ListViewItemStates.Selected) <> 0 Then
- ' e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds)
- 'End If
- ' Draw the progressbar.
- If e.ColumnIndex = Progressbar_Column Then
- ' Background color of the progressbar.
- e.Graphics.FillRectangle(_ProgressBar_BackColor, e.Bounds)
- ' Gradient to fill the progressbar.
- Dim brGradient As Brush = _
- New Drawing2D.LinearGradientBrush(New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), _
- _ProgressBar_FillColor1, _ProgressBar_FillColor2, 270, True)
- ' Draw the actual progressbar.
- e.Graphics.FillRectangle(brGradient, _
- e.Bounds.X + 1, e.Bounds.Y + 2, _
- CInt(((_ProgressPercent) / 100) * (e.Bounds.Width - 2)), e.Bounds.Height - 3)
- ' Draw the percentage number and percent sign.
- e.Graphics.DrawString(_ProgressPercent.ToString("n" & _ProgressPercent_Decimal) & _ProgressPercent_Text, _
- _ProgressPercent_Font, _ProgressPercent_ForeColor, _
- CSng(e.Bounds.X + (e.Bounds.Width / 2)), e.Bounds.Y + 3, _
- _ProgressPercent_StringFormat)
- ' Draw a light gray rectangle/border around the progressbar.
- e.Graphics.DrawRectangle(_ProgressBar_BorderColor, _
- e.Bounds.X, e.Bounds.Y + 1, _
- e.Bounds.Width - 1, e.Bounds.Height - 2)
- Else
- ' e.DrawDefault = True
- End If
- End Sub
- #End Region
- #End Region
- #Region " Undo/Redo Manager "
- #Region " Members "
- #Region " Properties "
- ''' <summary>
- ''' Enable or disble the Undo/Redo Manager system.
- ''' </summary>
- Public Property UndoRedo_Enabled As Boolean = False
- #End Region
- #Region " Delegates "
- ''' <summary>
- ''' Delegate to Add an Item for Undo/Redo operations.
- ''' </summary>
- Private Delegate Sub AddDelegate(item As ListViewItem)
- ''' <summary>
- ''' Delegate to Remove an Item for Undo/Redo operations.
- ''' </summary>
- Private Delegate Sub RemoveDelegate(item As ListViewItem)
- #End Region
- #Region " Other Objects "
- ''' <summary>
- ''' Stack to store Undo actions.
- ''' </summary>
- Public Undostack As New Stack(Of ListView_Action)
- ''' <summary>
- ''' Stack to store Redo actions.
- ''' </summary>
- Public Redostack As New Stack(Of ListView_Action)
- ''' <summary>
- ''' Flag to check if it is doing a Undo operation.
- ''' </summary>
- Private IsDoingUndo As Boolean = False
- ''' <summary>
- ''' Flag to check if it is doing a Redo operation.
- ''' </summary>
- Private IsDoingRedo As Boolean = False
- ''' <summary>
- ''' The Undo/Redo action.
- ''' </summary>
- Private action As ListView_Action = Nothing
- #End Region
- #Region " Enums "
- ''' <summary>
- ''' The operation.
- ''' </summary>
- Public Enum Operation As Short
- Undo = 0
- Redo = 1
- End Enum
- ''' <summary>
- ''' The kind of method for the Undo/Redo operation.
- ''' </summary>
- Public Enum Method As Short
- Add = 0
- Remove = 1
- End Enum
- #End Region
- #Region " Types "
- ''' <summary>
- ''' Creates a Undo/Redo Action.
- ''' </summary>
- Class ListView_Action
- ''' <summary>
- ''' Names the Undo/Redo Action.
- ''' </summary>
- Property Name As String
- ''' <summary>
- ''' Points to a method to excecute.
- ''' </summary>
- Property Operation As [Delegate]
- ''' <summary>
- ''' Method of the Undo/Redo operation.
- ''' </summary>
- Property Method As Method
- ''' <summary>
- ''' Data Array for the method to excecute.
- ''' </summary>
- Property Data As ListViewItem
- End Class
- #End Region
- #Region " Events "
- ''' <summary>
- ''' Event is raised after an Undo/Redo action is performed.
- ''' </summary>
- Public Event UndoRedo_IsPerformed As EventHandler(Of UndoneRedoneEventArgs)
- Public Class UndoneRedoneEventArgs : Inherits EventArgs
- Public Property Operation As Operation
- Public Property Method As Method
- Public Property Item As ListViewItem
- Public Property UndoStack As Stack(Of ListView_Action)
- Public Property RedoStack As Stack(Of ListView_Action)
- End Class
- ''' <summary>
- ''' Event is raised when Undo/Redo Stack size changed.
- ''' </summary>
- Public Event UndoRedo_StackSizeChanged As EventHandler(Of StackSizeChangedEventArgs)
- Public Class StackSizeChangedEventArgs : Inherits EventArgs
- Public Property UndoStack As Stack(Of ListView_Action)
- Public Property RedoStack As Stack(Of ListView_Action)
- Public Property UndoStackIsEmpty As Boolean
- Public Property RedoStackIsEmpty As Boolean
- End Class
- #End Region
- #End Region
- #Region " Public Methods "
- ''' <summary>
- ''' Undo the last action.
- ''' </summary>
- Public Sub Undo()
- If Me.Undostack.Count = 0 Then Exit Sub ' Nothing to Undo.
- Me.IsDoingUndo = True
- Me.action = Me.Undostack.Pop ' Get the Action from the Stack and remove it.
- Me.action.Operation.DynamicInvoke(Me.action.Data) ' Invoke the undo Action.
- Me.IsDoingUndo = False
- Raise_UndoRedo_IsPerformed(Operation.Undo, Me.action.Method, Me.action.Data)
- End Sub
- ''' <summary>
- ''' Redo the last action.
- ''' </summary>
- Public Sub Redo()
- If Me.Redostack.Count = 0 Then Exit Sub ' Nothing to Redo.
- Me.IsDoingRedo = True
- Me.action = Me.Redostack.Pop() ' Get the Action from the Stack and remove it.
- Me.action.Operation.DynamicInvoke(Me.action.Data) ' Invoke the redo Action.
- Me.IsDoingRedo = False
- Raise_UndoRedo_IsPerformed(Operation.Redo, Me.action.Method, Me.action.Data)
- End Sub
- #End Region
- #Region " Private Methods "
- ''' <summary>
- ''' Reverses an Undo/Redo action.
- ''' </summary>
- Private Function GetReverseAction(ByVal e As UndoneRedoneEventArgs) As ListView_Action
- Me.action = New ListView_Action
- Me.action.Name = e.Item.Text
- Me.action.Data = e.Item
- Me.action.Operation = If(e.Method = Method.Add, _
- New RemoveDelegate(AddressOf Me.RemoveItem), _
- New AddDelegate(AddressOf Me.AddItem))
- Me.action.Method = If(e.Method = Method.Add, _
- Method.Remove, _
- Method.Add)
- Return Me.action
- End Function
- ''' <summary>
- ''' Raises the "UndoRedo_IsPerformed" Event.
- ''' </summary>
- Private Sub Raise_UndoRedo_IsPerformed(ByVal Operation As Operation, _
- ByVal Method As Method, _
- ByVal Item As ListViewItem)
- RaiseEvent UndoRedo_IsPerformed(Me, New UndoneRedoneEventArgs _
- With {.Item = Item, _
- .Method = Method, _
- .Operation = Operation, _
- .UndoStack = Me.Undostack, _
- .RedoStack = Me.Redostack})
- Raise_UndoRedo_StackSizeChanged()
- End Sub
- ''' <summary>
- ''' Raises the "UndoRedo_StackSizeChanged" Event.
- ''' </summary>
- Private Sub Raise_UndoRedo_StackSizeChanged()
- RaiseEvent UndoRedo_StackSizeChanged(Me, New StackSizeChangedEventArgs _
- With {.UndoStack = Me.Undostack, _
- .RedoStack = Me.Redostack, _
- .UndoStackIsEmpty = Me.Undostack.Count = 0, _
- .RedoStackIsEmpty = Me.Redostack.Count = 0})
- End Sub
- #End Region
- #Region " Event Handlers "
- ''' <summary>
- ''' This handles when an Undo or Redo operation is performed.
- ''' </summary>
- Private Sub UndoneRedone(ByVal sender As Object, ByVal e As UndoneRedoneEventArgs) _
- Handles Me.UndoRedo_IsPerformed
- Select Case e.Operation
- Case Operation.Undo
- ' Create a Redo Action for the undone action.
- Me.Redostack.Push(GetReverseAction(e))
- Case Operation.Redo
- ' Create a Undo Action for the redone action.
- Me.Undostack.Push(GetReverseAction(e))
- End Select
- End Sub
- ''' <summary>
- ''' Monitors when an Item is added to create an Undo Operation.
- ''' </summary>
- Private Sub OnItemAdded(sender As Object, e As ItemAddedEventArgs) _
- Handles Me.ItemAdded
- If Me.UndoRedo_Enabled _
- AndAlso (Not Me.IsDoingUndo And Not Me.IsDoingRedo) Then
- Me.Redostack.Clear()
- ' // Crate an Undo Action
- Me.action = New ListView_Action
- Me.action.Name = e.Item.Text
- Me.action.Operation = New RemoveDelegate(AddressOf Me.RemoveItem)
- Me.action.Data = e.Item
- Me.action.Method = Method.Remove
- Me.Undostack.Push(action)
- Raise_UndoRedo_StackSizeChanged()
- End If
- End Sub
- ''' <summary>
- ''' Monitors when an Item is removed to create an Undo Operation.
- ''' </summary>
- Private Sub OnItemRemoved(sender As Object, e As ItemRemovedEventArgs) _
- Handles Me.ItemRemoved
- If Me.UndoRedo_Enabled _
- AndAlso (Not Me.IsDoingUndo And Not Me.IsDoingRedo) Then
- Me.Redostack.Clear()
- ' // Crate an Undo Action
- Me.action = New ListView_Action
- Me.action.Name = e.Item.Text
- Me.action.Operation = New AddDelegate(AddressOf Me.AddItem)
- Me.action.Data = e.Item
- Me.action.Method = Method.Add
- Me.Undostack.Push(action)
- Raise_UndoRedo_StackSizeChanged()
- End If
- End Sub
- #End Region
- #End Region
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement