Friend WithEvents StatusStrip1 As System.Windows.Forms.StatusStrip
Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents ToolStripMenuItem2 As System.Windows.Forms.ToolStripMenuItem
引用:
作者: Form1元件屬性
Private Sub InitializeComponent()
Me.StatusStrip1 = New System.Windows.Forms.StatusStrip
Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
Me.TabControl1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
Me.ToolStripMenuItem2 = New System.Windows.Forms.ToolStripMenuItem
Me.MenuStrip1.SuspendLayout()
Me.TabControl1.SuspendLayout()
Me.SuspendLayout()
'
'StatusStrip1
'
Me.StatusStrip1.Location = New System.Drawing.Point(0, 292)
Me.StatusStrip1.Name = "StatusStrip1"
Me.StatusStrip1.Size = New System.Drawing.Size(291, 22)
Me.StatusStrip1.TabIndex = 1
Me.StatusStrip1.Text = "StatusStrip1"
'
'MenuStrip1
'
Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem1})
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
Me.MenuStrip1.Name = "MenuStrip1"
Me.MenuStrip1.Size = New System.Drawing.Size(291, 24)
Me.MenuStrip1.TabIndex = 3
Me.MenuStrip1.Text = "MenuStrip1"
'
'TabControl1
'
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Dock = System.Windows.Forms.DockStyle.Top
Me.TabControl1.Location = New System.Drawing.Point(0, 24)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(291, 21)
Me.TabControl1.TabIndex = 4
'
'TabPage1
'
Me.TabPage1.Location = New System.Drawing.Point(4, 22)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage1.Size = New System.Drawing.Size(283, 0)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "菜單"
Me.TabPage1.UseVisualStyleBackColor = True
'
'TabPage2
'
Me.TabPage2.Location = New System.Drawing.Point(4, 22)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage2.Size = New System.Drawing.Size(345, 0)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "新菜單*"
Me.TabPage2.UseVisualStyleBackColor = True
'
'ToolStripMenuItem1
'
Me.ToolStripMenuItem1.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem2})
Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
Me.ToolStripMenuItem1.Size = New System.Drawing.Size(44, 20)
Me.ToolStripMenuItem1.Text = "系統"
'
'ToolStripMenuItem2
'
Me.ToolStripMenuItem2.Name = "ToolStripMenuItem2"
Me.ToolStripMenuItem2.Size = New System.Drawing.Size(152, 22)
Me.ToolStripMenuItem2.Text = "離開"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(291, 314)
Me.Controls.Add(Me.TabControl1)
Me.Controls.Add(Me.StatusStrip1)
Me.Controls.Add(Me.MenuStrip1)
Me.IsMdiContainer = True
Me.MainMenuStrip = Me.MenuStrip1
Me.MaximizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Form1"
Me.MenuStrip1.ResumeLayout(False)
Me.MenuStrip1.PerformLayout()
Me.TabControl1.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
引用:
作者: Form2需要元件
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
Friend WithEvents ToolStripLabel1 As System.Windows.Forms.ToolStripLabel
Friend WithEvents ToolStripComboBox1 As System.Windows.Forms.ToolStripComboBox
Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
Friend WithEvents Column1 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents Column2 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents Column3 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents Column4 As System.Windows.Forms.DataGridViewTextBoxColumn
Dim PageNo As Single = 1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Cursor = Cursors.WaitCursor
Dim f2 As Form2
f2 = New Form2
f2.MdiParent = Me
f2.Show()
Me.Cursor = Cursors.Default
End Sub
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedIndex + 1 = TabControl1.TabPages.Count Then
TabControl1.SelectedTab.Text = "菜單 - " + Str(PageNo)
TabControl1.SelectedTab.ImageIndex = 1
PageNo += 1
TabControl1.TabPages.Add("新菜單*")
TabControl1.TabPages(TabControl1.TabPages.Count - 1).ImageIndex = 2
Dim f2 As Form2
f2 = New Form2
f2.Text = TabControl1.SelectedTab.Text
f2.Tag = -1
f2.MdiParent = Me
f2.Show()
Else
Dim form As Form
For Each form In Me.MdiChildren
If form.Text = TabControl1.TabPages(TabControl1.SelectedIndex).Text Then form.Activate()
Next
End If
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
Close()
End Sub
End Class
引用:
作者: Form2程式碼
Public Class Form2
Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
DataGridView1.Rows.Add("牛肉麵", "100", "0", "0")
DataGridView1.Rows.Add("炸醬麵", "60", "0", "0")
DataGridView1.Rows.Add("滷肉飯", "50", "0", "0")
DataGridView1.Rows.Add("水餃", "5", "0", "0")
DataGridView1.Rows.Add("貢丸湯", "30", "0", "0")
End Sub
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Dim i As Integer, n As Integer = 0
For i = 0 To DataGridView1.Rows.Count - 2
If Val(DataGridView1.Rows(i).Cells(1).Value) > 0 And Val(DataGridView1.Rows(i).Cells(2).Value) > 0 Then DataGridView1.Rows(i).Cells(3).Value = Val(DataGridView1.Rows(i).Cells(1).Value) * Val(DataGridView1.Rows(i).Cells(2).Value)
n = n + (Val(DataGridView1.Rows(i).Cells(1).Value) * Val(DataGridView1.Rows(i).Cells(2).Value))
Next
TextBox1.Text = Format(n, "NT$ #,###,###.#")
End Sub
Private Sub ToolStripComboBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripComboBox1.TextChanged
Dim i As Integer
For i = 0 To Form1.TabControl1.TabCount - 1
If Form1.TabControl1.TabPages(i).Text = Me.Text Then Form1.TabControl1.TabPages(i).Text = ToolStripComboBox1.Text : Me.Text = ToolStripComboBox1.Text : Exit For
Next
End Sub
End Class