form1.vb
来自「vb 应用实例 简单应用 dddddddddddddddddddddddddd」· VB 代码 · 共 132 行
VB
132 行
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
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
Private components As System.ComponentModel.IContainer
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.DataGrid1 = New System.Windows.Forms.DataGrid()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label1 = New System.Windows.Forms.Label()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.Button1.Location = New System.Drawing.Point(131, 109)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(122, 24)
Me.Button1.TabIndex = 11
Me.Button1.Text = "Add"
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(38, 157)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(308, 80)
Me.DataGrid1.TabIndex = 10
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(90, 61)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(225, 21)
Me.TextBox2.TabIndex = 9
Me.TextBox2.Text = "Taipei"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(90, 29)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(225, 21)
Me.TextBox1.TabIndex = 8
Me.TextBox1.Text = "Jack"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.Label2.Location = New System.Drawing.Point(28, 69)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(29, 14)
Me.Label2.TabIndex = 7
Me.Label2.Text = "City"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.Label1.Location = New System.Drawing.Point(28, 37)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(29, 14)
Me.Label1.TabIndex = 6
Me.Label1.Text = "Name"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(373, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.DataGrid1, Me.TextBox2, Me.TextBox1, Me.Label2, Me.Label1})
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Data"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add(Label1.Text)
dt.Columns.Add(Label2.Text)
DataGrid1.DataSource = dt
End Sub
Private dt As New DataTable("Names")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dr As DataRow = dt.NewRow()
dr.Item(Label1.Text) = TextBox1.Text
dr.Item(Label2.Text) = TextBox2.Text
dt.Rows.Add(dr)
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?