📄 form1.vb
字号:
ListBox1.Items.Add(prc1)
Next
ListBox1.Sorted = True
StatusBar1.Text = "执行当中的所有 Process"
Catch e1 As Exception
MessageBox.Show(e1.Message, Me.Text)
End Try
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Try
StatusBar1.Text = CType(ListBox1.SelectedItem, Process).MainModule.FileName
Catch e1 As Exception
StatusBar1.Text = String.Empty
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim dt1 As DataTable = FillTable("C:\")
If Not (dt1 Is Nothing) Then
ListBox2.DisplayMember = "MyFileName"
ListBox2.ValueMember = "MyLength"
ListBox2.DataSource = dt1
End If
StatusBar1.Text = "C:\ 的档案"
Catch e1 As Exception
MessageBox.Show(e1.Message, Me.Text)
End Try
End Sub
Private Function FillTable(ByVal Path As String) As DataTable
Dim dt1 As New DataTable()
Dim dr1 As DataRow
Try
'DataTable 字段类型
dt1.Columns.Add("MyFileName", GetType(System.String))
dt1.Columns.Add("MyLength", GetType(System.Int64))
Dim di1 As New DirectoryInfo(Path)
Dim fi1 As FileInfo
'所有档案 FileName & Length -> DataTable
For Each fi1 In di1.GetFiles()
If (fi1.Attributes And (FileAttributes.Hidden Or FileAttributes.System)) = 0 Then
dr1 = dt1.NewRow()
dr1("MyFileName") = fi1.Name
dr1("MyLength") = fi1.Length
dt1.Rows.Add(dr1)
End If
Next
Catch e1 As Exception
MessageBox.Show(e1.Message, Me.Text)
End Try
Return dt1
End Function
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
StatusBar1.Text = "档案大小: " & ListBox2.SelectedValue.ToString
End Sub
'Set ListBox3 SelectionMode = MultiSimple
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
Dim di As New DirectoryInfo("C:\")
ListBox3.DisplayMember = "Name"
ListBox3.ValueMember = "Length"
ListBox3.DataSource = di.GetFiles()
Catch e1 As Exception
MessageBox.Show(e1.Message, Me.Text)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'列出所有可以选择的模式(), SelectionMode: 指定清单方块的选取行为
ComboBox1.DataSource = System.Enum.GetNames(GetType(SelectionMode))
ComboBox1.SelectedIndex = 2
'ComboBoxStyle: ComboBox 样式
ComboBox3.DataSource = System.Enum.GetNames(GetType(ComboBoxStyle))
NumericUpDown1.Value = ComboBox2.DropDownWidth
NumericUpDown2.Value = ComboBox2.MaxDropDownItems
ComboBox3.SelectedIndex = 1
End Sub
Private Sub ListBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox3.SelectedIndexChanged
Try
Dim i(ListBox3.SelectedIndices.Count - 1) As Integer
ListBox3.SelectedIndices.CopyTo(i, 0)
ListBox4.DataSource = i
ListBox5.Items.Clear()
ListBox5.BeginUpdate()
Dim fi1 As FileInfo
For Each fi1 In ListBox3.SelectedItems
ListBox5.Items.Add(fi1.Name)
Next
ListBox5.EndUpdate()
Catch e1 As Exception
ListBox4.DataSource = Nothing
End Try
End Sub
'SelectionMode
'MultiExtended 可以选取多重项目,且使用者可以压住 SHIFT、CTRL 和方向键进行选取。
'MultiSimple 可以选取多重项目(不需压住任何键)。
'None 没有可选取项目。
'One 只能选取一个项目
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
ListBox3.ClearSelected()
ListBox3.SelectionMode = CType(System.Enum.Parse(GetType(SelectionMode), ComboBox1.Text), SelectionMode)
Catch e1 As Exception
MessageBox.Show(e1.Message, Me.Text)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
'Dim prc As Process
'BindToArray
ListBox6.ValueMember = "MainModule"
ListBox6.DisplayMember = "ProcessName"
ListBox6.DataSource = Process.GetProcesses()
Catch e1 As Exception
MessageBox.Show(e1.Message, Me.Text)
End Try
End Sub
Private Sub ListBox6_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox6.SelectedIndexChanged
Try
StatusBar1.Text = CType(ListBox6.SelectedValue, ProcessModule).FileName
Catch e1 As Exception
StatusBar1.Text = String.Empty
End Try
End Sub
'需先由 [服务器总管] 将 Northwind 之 Product 数据表拖拉到 Form1
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Try
Dim ds1 As New DataSet()
SqlDataAdapter1.Fill(ds1)
ComboBox2.ValueMember = "ProductID"
ComboBox2.DisplayMember = "ProductName"
ComboBox2.DataSource = ds1.Tables(0)
Catch e1 As Exception
MessageBox.Show(e1.Message, Me.Text)
End Try
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
StatusBar1.Text = ComboBox2.SelectedValue.ToString
End Sub
'DropDownStyle: ComboBox 样式
'DropDown 文字部份为可编辑的。使用者必须按一下箭头按钮以显示清单部份。
'DropDownList 使用者不能直接编辑文字部份。使用者必须按一下箭头按钮以显示清单部份。
'Simple 文字部份为可编辑的。清单部份是永远可见的
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
ComboBox2.DropDownStyle = CType(System.Enum.Parse(GetType(ComboBoxStyle), ComboBox3.Text), ComboBoxStyle)
End Sub
'DropDownWidth: 下拉式方块下拉部份的宽度。
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
ComboBox2.DropDownWidth = CInt(NumericUpDown1.Value)
End Sub
'MaxDropDownItems: 下拉部份中显示项目的最大数目。
Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
ComboBox2.MaxDropDownItems = CInt(NumericUpDown2.Value)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -