| 1 |
#Region "Microsoft.VisualBasic::29a9366500996532fe82cc1072f8675c, Microsoft.VisualBasic.Core\ApplicationServices\Tools\WinForm\Extensions.vb"
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#End Region
|
| 46 |
|
| 47 |
Imports System.Runtime.CompilerServices
|
| 48 |
Imports Microsoft.VisualBasic.Linq
|
| 49 |
Imports Keyboard = System.Windows.Forms.Keys
|
| 50 |
|
| 51 |
Namespace Windows.Forms
|
| 52 |
|
| 53 |
Public Module Extensions
|
| 54 |
|
| 55 |
ReadOnly chars As New Dictionary(Of Keys, Char)
|
| 56 |
|
| 57 |
<Extension>
|
| 58 |
Public Function IsPrintableCharacter(key As Keys) As Boolean
|
| 59 |
Return chars.ContainsKey(key)
|
| 60 |
End Function
|
| 61 |
|
| 62 |
<Extension>
|
| 63 |
Public Function ToChar(key As Keys) As Char
|
| 64 |
If Not key.IsPrintableCharacter Then
|
| 65 |
Return Nothing
|
| 66 |
Else
|
| 67 |
Return chars(key)
|
| 68 |
End If
|
| 69 |
End Function
|
| 70 |
|
| 71 |
Sub New()
|
| 72 |
chars(Keyboard.A) = "a"
|
| 73 |
chars(Keyboard.B) = "b"
|
| 74 |
chars(Keyboard.C) = "c"
|
| 75 |
chars(Keyboard.D) = "d"
|
| 76 |
chars(Keyboard.E) = "e"
|
| 77 |
chars(Keyboard.F) = "f"
|
| 78 |
chars(Keyboard.G) = "g"
|
| 79 |
chars(Keyboard.H) = "h"
|
| 80 |
chars(Keyboard.I) = "i"
|
| 81 |
chars(Keyboard.J) = "j"
|
| 82 |
chars(Keyboard.K) = "k"
|
| 83 |
chars(Keyboard.L) = "l"
|
| 84 |
chars(Keyboard.M) = "m"
|
| 85 |
chars(Keyboard.N) = "n"
|
| 86 |
chars(Keyboard.O) = "o"
|
| 87 |
chars(Keyboard.P) = "p"
|
| 88 |
chars(Keyboard.Q) = "q"
|
| 89 |
chars(Keyboard.R) = "r"
|
| 90 |
chars(Keyboard.S) = "s"
|
| 91 |
chars(Keyboard.T) = "t"
|
| 92 |
chars(Keyboard.U) = "u"
|
| 93 |
chars(Keyboard.V) = "v"
|
| 94 |
chars(Keyboard.W) = "w"
|
| 95 |
chars(Keyboard.X) = "x"
|
| 96 |
chars(Keyboard.Y) = "y"
|
| 97 |
chars(Keyboard.Z) = "z"
|
| 98 |
chars(Keyboard.D0) = "0" : chars(Keyboard.NumPad0) = "0"
|
| 99 |
chars(Keyboard.D0) = "1" : chars(Keyboard.NumPad0) = "1"
|
| 100 |
chars(Keyboard.D0) = "2" : chars(Keyboard.NumPad0) = "2"
|
| 101 |
chars(Keyboard.D0) = "3" : chars(Keyboard.NumPad0) = "3"
|
| 102 |
chars(Keyboard.D0) = "4" : chars(Keyboard.NumPad0) = "4"
|
| 103 |
chars(Keyboard.D0) = "5" : chars(Keyboard.NumPad0) = "5"
|
| 104 |
chars(Keyboard.D0) = "6" : chars(Keyboard.NumPad0) = "6"
|
| 105 |
chars(Keyboard.D0) = "7" : chars(Keyboard.NumPad0) = "7"
|
| 106 |
chars(Keyboard.D0) = "8" : chars(Keyboard.NumPad0) = "8"
|
| 107 |
chars(Keyboard.D0) = "9" : chars(Keyboard.NumPad0) = "9"
|
| 108 |
End Sub
|
| 109 |
|
| 110 |
<Extension>
|
| 111 |
Public Sub AddRowData(view As DataGridView, name$, ParamArray values As Object())
|
| 112 |
Call view.Rows.Add(values)
|
| 113 |
Dim count = view.RowCount
|
| 114 |
view.Rows(count - 1).HeaderCell.Value = name
|
| 115 |
End Sub
|
| 116 |
|
| 117 |
<Extension>
|
| 118 |
Public Sub Clear(view As DataGridView)
|
| 119 |
Call view.Columns.Clear()
|
| 120 |
Call view.Rows.Clear()
|
| 121 |
End Sub
|
| 122 |
|
| 123 |
<Extension>
|
| 124 |
Public Function AddFilesHistory(ByRef menu As ToolStripMenuItem, files As IEnumerable(Of String), invoke As Action(Of String), Optional formats As Func(Of String, String) = Nothing) As Boolean
|
| 125 |
If formats Is Nothing Then
|
| 126 |
formats = Function(path$) path$.FileName & $" ({Mid(path, 1, 30)}...)"
|
| 127 |
End If
|
| 128 |
|
| 129 |
For Each path$ In files.SafeQuery
|
| 130 |
Dim file As New ToolStripMenuItem With {
|
| 131 |
.Text = formats(path),
|
| 132 |
.AutoToolTip = True,
|
| 133 |
.ToolTipText = path
|
| 134 |
}
|
| 135 |
|
| 136 |
AddHandler file.Click,
|
| 137 |
Sub(sender, arg)
|
| 138 |
Call invoke(path)
|
| 139 |
End Sub
|
| 140 |
|
| 141 |
Call menu.DropDownItems.Add(file)
|
| 142 |
Next
|
| 143 |
|
| 144 |
Return True
|
| 145 |
End Function
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
<Extension>
|
| 155 |
Public Sub AddFileHistory(ByRef files As List(Of String), path$, Optional latestFirst As Boolean = True)
|
| 156 |
If files Is Nothing Then
|
| 157 |
files = New List(Of String)
|
| 158 |
End If
|
| 159 |
|
| 160 |
Dim n As Integer = files.IndexOf(path)
|
| 161 |
|
| 162 |
If n <> -1 Then
|
| 163 |
Call files.RemoveAt(n)
|
| 164 |
End If
|
| 165 |
|
| 166 |
If latestFirst Then
|
| 167 |
Call files.Insert(Scan0, path)
|
| 168 |
Else
|
| 169 |
Call files.Add(path)
|
| 170 |
End If
|
| 171 |
End Sub
|
| 172 |
|
| 173 |
<Extension>
|
| 174 |
Public Sub WriteLine(tb As TextBox, s$)
|
| 175 |
Call tb.AppendText(s & vbCrLf)
|
| 176 |
End Sub
|
| 177 |
End Module
|
| 178 |
End Namespace
|