'Public Shared Function GetFilePathsExtension(ByVal path As String, ByVal ParamArray patterns As String()) As StringList
'    Dim items As New StringList

'    For Each i As String In GetFilePaths(path)
'        For Each i2 As String In patterns
'            If i.ToLower.EndsWith(i2.ToLower) Then
'                items.Add(i)
'            End If
'        Next
'    Next

'    items.Sort()

'    Return items
'End Function

'Public Shared Function GetFilePathsRegex(ByVal path As String, ByVal ParamArray patterns As String()) As StringList
'    Dim items As New StringList

'    For Each i As String In GetFilePaths(path)
'        For Each i2 As String In patterns
'            If Regex.IsMatch(Filepath.GetNameWithExt(i), i2) Then
'                items.Add(i)
'            End If
'        Next
'    Next

'    items.Sort()

'    Return items
'End Function

'Public Shared Function FindNotExistingName(ByVal path As String) As String
'    Dim x As Integer
'    Dim tempPath As String = path

'    While Directory.Exists(path)
'        x += 1
'        path = tempPath + x.ToString
'    End While

'    Return path
'End Function

'Public Shared Function GetOutput(ByVal path As String, ByVal arguments As String) As String
'    Dim p As New Process
'    p.StartInfo.RedirectStandardOutput = True
'    p.StartInfo.UseShellExecute = False
'    p.StartInfo.FileName = path
'    p.StartInfo.Arguments = arguments
'    p.StartInfo.CreateNoWindow = True
'    p.Start()
'    p.WaitForExit()
'    Dim ret As String = p.StandardOutput.ReadToEnd()
'    p.StandardOutput.Close()
'    p.Close()
'    Return ret
'End Function

'Imports System.Drawing.Drawing2D

'Public Class GradientLabel
'    Inherits Label

'    Private cLeft As Color
'    Private cRight As Color

'    Public Property BeginColor() As Color
'        Get
'            Return cLeft
'        End Get
'        Set(ByVal Value As Color)
'            cLeft = Value
'        End Set
'    End Property

'    Public Property EndColor() As Color
'        Get
'            Return cRight
'        End Get
'        Set(ByVal Value As Color)
'            cRight = Value
'        End Set
'    End Property

'    Public Sub New()
'        cLeft = SystemColors.ActiveCaption
'        cRight = SystemColors.Control
'    End Sub

'    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
'        Dim GBrush As LinearGradientBrush = New LinearGradientBrush( _
'            New Point(0, 0), New Point(Width, 0), cLeft, cRight)
'        Dim rect As Rectangle = New Rectangle(0, 0, Width, Height)
'        e.Graphics.FillRectangle(GBrush, rect)
'        Dim drawBrush As SolidBrush = New SolidBrush(ForeColor)
'        Dim sf As StringFormat = New StringFormat
'        sf.Alignment = StringAlignment.Center
'        Dim rectF As RectangleF = New RectangleF(0, Convert.ToSingle( _
'            Height / 2 - Font.Height / 2), Width, Height)
'        e.Graphics.DrawString(Me.Text, Me.Font, drawBrush, rectF, sf)
'    End Sub
'End Class

'<ProvideProperty("Modifier_MenuItemKeyProvider", GetType(MenuItem)), _
'    ProvideProperty("Key_MenuItemKeyProvider", GetType(MenuItem)), _
'    ProvideProperty("Handle_MenuItemKeyProvider", GetType(MenuItem))> _
'    Public Class MenuItemKeyProvider
'    Inherits Component
'    Implements IExtenderProvider

'    Private _Modifier As New Hashtable
'    Private _Key As New Hashtable
'    Private _Handle As New Hashtable

'    Public Function CanExtend(ByVal o As Object) As Boolean Implements System.ComponentModel.IExtenderProvider.CanExtend
'        Return TypeOf o Is MenuItem
'    End Function

'    <Category("_MenuItemKeyProvider"), DefaultValue("")> _
'    Public Function GetModifier_MenuItemKeyProvider(ByVal mi As MenuItem) As String
'        If _Modifier.ContainsKey(mi) Then
'            Return CStr(_Modifier(mi))
'        End If

'        Return ""
'    End Function

'    <Category("_MenuItemKeyProvider")> _
'    Public Sub SetModifier_MenuItemKeyProvider(ByVal mi As MenuItem, ByVal value As String)
'        _Modifier(mi) = value
'    End Sub

'    <Category("_MenuItemKeyProvider"), DefaultValue("")> _
'    Public Function GetKey_MenuItemKeyProvider(ByVal mi As MenuItem) As String
'        If _Key.ContainsKey(mi) Then
'            Return CStr(_Key(mi))
'        End If

'        Return ""
'    End Function

'    <Category("_MenuItemKeyProvider")> _
'    Public Sub SetKey_MenuItemKeyProvider(ByVal mi As MenuItem, ByVal value As String)
'        _Key(mi) = value
'    End Sub

'    <Category("_MenuItemKeyProvider"), DefaultValue(GetType(Keys), "")> _
'    Public Function GetHandle_MenuItemKeyProvider(ByVal mi As MenuItem) As Boolean
'        If _Handle.ContainsKey(mi) Then
'            Return CBool(_Handle(mi))
'        End If

'        Return True
'    End Function

'    <Category("_MenuItemKeyProvider")> _
'    Public Sub SetHandle_MenuItemKeyProvider(ByVal mi As MenuItem, ByVal h As Boolean)
'        _Handle(mi) = h
'    End Sub

'    Public Sub Init(ByVal c As Control)
'        Dim text As String

'        AddHandler c.KeyDown, AddressOf OnKeyDown

'        For Each i As MenuItem In _Key.Keys
'            text = GetString(GetKey(_Modifier(i)), GetKey(_Key(i)))

'            If text <> "" Then
'                i.Text += vbTab + text
'            End If
'        Next
'    End Sub

'    Private Function GetKey(ByVal o As Object) As Keys
'        If o Is Nothing OrElse CStr(o) = "" Then
'            Return Keys.None
'        End If

'        Return CType(TypeDescriptor.GetConverter(GetType(Keys)).ConvertFrom(o), Keys)
'    End Function

'    Public Sub OnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
'        For Each i As MenuItem In _Key.Keys
'            Dim modifier As Keys = GetKey(_Modifier(i))
'            Dim key As Keys = GetKey(_Key(i))

'            If e.KeyData = (modifier Or key) AndAlso _
'                CBool(_Handle(i)) AndAlso i.Enabled Then
'                i.PerformClick()
'            End If
'        Next
'    End Sub

'    Private Function GetKeyName(ByVal k As Keys) As String
'        Dim s As String = k.ToString()

'        If s.Length > 1 Then
'            Select Case s
'                Case "Control"
'                    s = "Ctrl"
'                Case "OemQuestion"
'                    s = "#"
'                Case "Prior"
'                    s = "Page Up"
'                Case "Next"
'                    s = "Page Down"
'                Case "Add"
'                    s = "Numpad" + " " + "Plus"
'                Case "Subtract"
'                    s = "Numpad" + " " + "Minus"
'                Case "Oemplus"
'                    s = "Plus"
'                Case "OemMinus"
'                    s = "Minus"
'            End Select
'        End If

'        Return s
'    End Function

'    Public Function GetString(ByVal modifier As Keys, ByVal key As Keys) As String
'        If key <> Keys.None Then
'            If modifier = Keys.None Then
'                Return GetKeyName(key)
'            Else
'                Return GetKeyName(modifier) + "+" + GetKeyName(key)
'            End If
'        End If

'        Return ""
'    End Function
'End Class

'Public Class ComboBoxEnumItemsManager(Of T)
'    Private Box As ComboBox

'    Public Sub New(ByVal comboBox As ComboBox)
'        Box = comboBox
'    End Sub

'    Public Sub Add(ByVal text As String, ByVal value As T)
'        Box.Items.Add(New ListBag(Of T)(text, value))
'    End Sub

'    Public Sub SelectItem(ByVal value As T)
'        Dim o As Object = Nothing

'        For Each i As ListBag(Of T) In Box.Items
'            If i.Value.Equals(value) Then
'                o = i
'            End If
'        Next

'        Box.SelectedItem = o
'    End Sub

'    Public Function GetValue() As T
'        If Not Box.SelectedItem Is Nothing Then
'            Return CType(Box.SelectedItem, ListBag(Of T)).Value
'        End If
'    End Function
'End Class

'Public Class ExtendedPanel
'    Inherits Panel

'    Public Sub New()
'        Padding = New Padding(8)
'    End Sub

'    Private TabPageStyleValue As Boolean

'    <Category("ExtendedPanel"), DefaultValue(False)> _
'    Public Property TabPageStyle() As Boolean
'        Get
'            Return TabPageStyleValue
'        End Get
'        Set(ByVal Value As Boolean)
'            TabPageStyleValue = Value

'            If Value Then
'                BackColor = Color.Transparent
'            End If

'            Invalidate()
'        End Set
'    End Property

'    <Category("Appearance"), DefaultValue(""), Browsable(True), _
'    EditorBrowsable(EditorBrowsableState.Always)> _
'    Public Overrides Property Text() As String
'        Get
'            Return MyBase.Text
'        End Get
'        Set(ByVal value As String)
'            MyBase.Text = value

'            Dim p As Padding = Padding
'            p.Top = Font.Height + 15
'            Padding = p

'            Invalidate()
'        End Set
'    End Property

'    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
'        MyBase.OnPaint(e)

'        If TabPageStyle Then
'            Theme.DrawBackground(Me, "TAB", Part.TABP_PANE, 0, e.Graphics, ClientRectangle)
'        End If

'        If Text <> "" Then
'            Dim b As New SolidBrush(ForeColor)
'            Dim f As Font = New Font(Font, FontStyle.Bold)
'            e.Graphics.DrawString(Text, f, b, Padding.Left, 6)
'            b.Dispose()

'            Dim size As SizeF = e.Graphics.MeasureString(Text, Font)

'            If Enabled Then
'                Dim p As New Pen(SystemColors.ControlDark)
'                e.Graphics.DrawLine(p, Padding.Left + 3, Font.Height + 10, Width - Padding.Right - 6, Font.Height + 10)
'                p.Dispose()

'                e.Graphics.DrawLine(Pens.White, Padding.Left + 3, Font.Height + 11, Width - Padding.Right - 6, Font.Height + 11)

'                Dim offset As Integer = 1
'                Dim visibleWidth As Integer = Width - 5
'            Else
'                Dim p As New Pen(SystemColors.InactiveBorder)
'                e.Graphics.DrawLine(p, Padding.Left + 3, Font.Height + 11, Width - Padding.Right - 6, Font.Height + 11)
'                p.Dispose()
'            End If
'        End If
'    End Sub
'End Class

'<Serializable()> _
'Public Class SmartSerialize
'    Implements ISerializable

'    Public Sub New()
'        'MyBase.New()
'    End Sub

'    <DebuggerNonUserCode()> _
'    Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
'        Dim t As Type = Me.GetType

'        While Not t Is GetType(Object)
'            For Each i As FieldInfo In t.GetFields(BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.DeclaredOnly)
'                Try
'                    i.SetValue(Me, info.GetValue(i.Name + GetVersion(i), i.FieldType))
'                Catch
'                End Try
'            Next

'            t = t.BaseType
'        End While

'        Init()
'    End Sub

'    Public Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext) Implements ISerializable.GetObjectData
'        Dim t As Type = Me.GetType

'        While Not t Is GetType(Object)
'            For Each i As FieldInfo In t.GetFields(BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.DeclaredOnly)
'                info.AddValue(i.Name + GetVersion(i), i.GetValue(Me))
'            Next

'            t = t.BaseType
'        End While
'    End Sub

'    Protected Overridable Sub Init()
'    End Sub

'    Private Function GetVersion(ByVal fi As FieldInfo) As String
'        Dim a As VersionAttribute() = CType(fi.GetCustomAttributes(GetType(VersionAttribute), True), VersionAttribute())

'        If a.Length > 0 Then
'            Return a(0).Version
'        End If

'        Return ""
'    End Function
'End Class


'<Serializable()> _
'Public Class Test2
'    Inherits Test

'    Public Sub New()
'        'MyBase.New()
'    End Sub

'    Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
'        MyBase.New(info, context)
'    End Sub

'    <Version("002")> Public Arthur As String

'    Protected Overrides Sub Init()
'        MyBase.Init()

'        If Arthur Is Nothing Then
'            Arthur = "Cool"
'        End If
'    End Sub
'End Class

'<Serializable()> _
'Public Class Test
'    Inherits SmartSerialize

'    Public Sub New()
'        'MyBase.New()
'    End Sub

'    Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
'        MyBase.New(info, context)
'    End Sub

'    <Version("000")> Public Dough As String

'    Protected Overrides Sub Init()
'        MyBase.Init()

'        If Dough Is Nothing Then
'            Dough = "full"
'        End If
'    End Sub
'End Class

'Public Class Download
'    Private Response As WebResponse
'    Private Request As WebRequest
'    Private Buffer As Byte() = New Byte(1023) {}
'    Private RemoteStream As Stream
'    Private LocalStream As Stream
'    Private Closed As Boolean

'    Public URI As String
'    Public Filename As String
'    Public Domain As String
'    Public Port As String
'    Public Username As String
'    Public Password As String
'    Public Size As Integer

'    Public Event ProgressChanged(ByVal size As Integer)
'    Public Event Completed()

'    Public Sub Start()
'        Request = WebRequest.Create(URI)

'        If StringHelp.ContainsValue(Domain, Port) Then
'            Request.Proxy = New WebProxy("http://" + Domain + ":" + Port + "/", True)
'        End If

'        If StringHelp.ContainsValue(Username, Password, Domain) Then
'            Dim nn As NetworkCredential = New NetworkCredential(Username, Password, Domain)
'            Dim cc As CredentialCache = New CredentialCache
'            cc.Add(New Uri(URI), "Basic", nn)
'            Request.Credentials = cc
'        End If

'        LocalStream = File.Create(Filename)
'        Request.BeginGetResponse(AddressOf ResponseCallback, Nothing)
'    End Sub

'    Private Sub ResponseCallback(ByVal ias As IAsyncResult)
'        Try
'            Response = Request.EndGetResponse(ias)
'            Size = CInt(Response.Headers("Content-Length"))
'            RemoteStream = Response.GetResponseStream()

'            RemoteStream.BeginRead(Buffer, 0, Buffer.Length, _
'                New AsyncCallback(AddressOf ReadCallback), Nothing)
'        Catch ex As Exception
'            CloseStreams()
'            Throw
'        End Try
'    End Sub

'    Private Sub ReadCallback(ByVal ias As IAsyncResult)
'        Try
'            Dim read As Integer = RemoteStream.EndRead(ias)

'            If read > 0 Then
'                LocalStream.Write(Buffer, 0, read)

'                If Not Closed Then
'                    RaiseEvent ProgressChanged(CInt(LocalStream.Length))
'                End If

'                RemoteStream.BeginRead(Buffer, 0, Buffer.Length, _
'                    New AsyncCallback(AddressOf ReadCallback), Nothing)
'            Else
'                If Not Closed Then
'                    CloseStreams()
'                    RaiseEvent Completed()
'                End If
'            End If
'        Catch ex As Exception
'            CloseStreams()
'            Throw
'        End Try
'    End Sub

'    Private Sub CloseStreams()
'        Closed = True
'        If Not Response Is Nothing Then Response.Close()
'        If Not RemoteStream Is Nothing Then RemoteStream.Close()
'        If Not LocalStream Is Nothing Then LocalStream.Close()
'    End Sub

'    Public Sub Abort()
'        CloseStreams()
'    End Sub
'End Class

'Public Shared Sub NewISerializable(ByVal instance As Object, ByVal info As SerializationInfo, ByVal context As StreamingContext)
'    Dim t As Type = instance.GetType
'    Dim instanceNew As Object = Activator.CreateInstance(t)

'    For Each iInfoOwnerField As FieldInfo In t.GetFields()
'        Try
'            Dim customBagValue As Object = info.GetValue(iInfoOwnerField.Name, iInfoOwnerField.FieldType)
'            Dim instanceBagValue As Object = iInfoOwnerField.GetValue(instanceNew)
'            Dim bagInfo As FieldInfo = t.GetField(iInfoOwnerField.Name)

'            For Each iInfoBagField As FieldInfo In bagInfo.FieldType.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic)
'                If iInfoBagField.IsNotSerialized Then
'                    iInfoBagField.SetValue(customBagValue, iInfoBagField.GetValue(instanceBagValue))
'                End If
'            Next

'            iInfoOwnerField.SetValue(instance, customBagValue)
'        Catch
'        End Try
'    Next
'End Sub

'Public Shared Function IsTextValid(ByVal c As Control, ByVal regexPattern As String, ByVal defaultValue As String) As Boolean
'    If Not Regex.IsMatch(c.Text, regexPattern) Then
'        Msg.Show("Input is not valid!", MsgIcon.Error)
'        c.Text = defaultValue
'        Return False
'    Else
'        Return True
'    End If
'End Function

'Public Class ControlHelp
'    Public Shared Sub DrawMovingText(ByVal c As Control, ByVal text As String)
'        If text = "" OrElse text Is Nothing Then
'            Exit Sub
'        End If

'        Dim bc As Color = c.BackColor

'        Dim textLength As Integer = CInt(c.CreateGraphics().MeasureString( _
'            text, c.Font).Width)

'        For i As Integer = c.Width To -textLength Step -1
'            Thread.Sleep(5)

'            c.CreateGraphics().Clear(bc)

'            c.CreateGraphics().DrawString(text, c.Font, _
'                New SolidBrush(c.ForeColor), New PointF(i, 0))
'        Next
'    End Sub

'    Public Shared Sub AdjustWidth(ByVal parentControl As Control, ByVal leftControl As Control, ByVal rightControl As Control)
'        leftControl.Left = 8
'        leftControl.Width = (parentControl.Width - 3 * 8) \ 2
'        rightControl.Width = leftControl.Width
'        rightControl.Left = leftControl.Width + 16
'    End Sub
'End Class

'Public Class StringArrayTypeEditor
'    Inherits UITypeEditor

'    Public Overloads Overrides Function EditValue(ByVal context As ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object
'        Dim f As StringEditorForm = CreateStringEditorForm()

'        f.tb.Text = String.Join(vbCrLf, DirectCast(value, String())).ToString

'        If f.ShowDialog() = DialogResult.OK Then
'            Return StringHelp.Split(StringHelp.FixBreak( _
'                f.tb.Text), Environment.NewLine)
'        Else
'            Return DirectCast(value, String())
'        End If
'    End Function

'    Public Overridable Function CreateStringEditorForm() As StringEditorForm
'        Return New StringEditorForm
'    End Function

'    Public Overloads Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
'        Return UITypeEditorEditStyle.Modal
'    End Function
'End Class