VB.Net Tutorial/GUI/MDI
Версия от 16:40, 26 мая 2010; (обсуждение)
Содержание
Add children form to parent form
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
public class MDIAddChildToParent
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Public mycount As Integer
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
Dim i As Integer
Dim newdoc As Form2
mycount = mycount + 1
newdoc = New Form2()
newdoc.Text = "Doc" + Str(mycount)
newdoc.MdiParent = Me
newdoc.Show()
End Sub
Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem6.Click
Me.ActiveMdiChild.Text = Me.ActiveMdiChild.Text
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem
Me.ToolStripMenuItem2 = New System.Windows.Forms.ToolStripMenuItem
Me.ToolStripMenuItem3 = New System.Windows.Forms.ToolStripMenuItem
Me.ToolStripMenuItem4 = New System.Windows.Forms.ToolStripMenuItem
Me.ToolStripMenuItem5 = New System.Windows.Forms.ToolStripMenuItem
Me.ToolStripMenuItem6 = New System.Windows.Forms.ToolStripMenuItem
Me.MenuStrip1.SuspendLayout()
Me.SuspendLayout()
"
"MenuStrip1
"
Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem1, Me.ToolStripMenuItem5})
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
Me.MenuStrip1.MdiWindowListItem = Me.ToolStripMenuItem5
Me.MenuStrip1.Name = "MenuStrip1"
Me.MenuStrip1.Padding = New System.Windows.Forms.Padding(8, 2, 0, 2)
Me.MenuStrip1.Size = New System.Drawing.Size(569, 24)
Me.MenuStrip1.TabIndex = 2
Me.MenuStrip1.Text = "MenuStrip1"
"
"ToolStripMenuItem1
"
Me.ToolStripMenuItem1.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem2, Me.ToolStripMenuItem3, Me.ToolStripMenuItem4})
Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
Me.ToolStripMenuItem1.Size = New System.Drawing.Size(49, 20)
Me.ToolStripMenuItem1.Text = "File"
"
"ToolStripMenuItem2
"
Me.ToolStripMenuItem2.Name = "ToolStripMenuItem2"
Me.ToolStripMenuItem2.Size = New System.Drawing.Size(152, 22)
Me.ToolStripMenuItem2.Text = "new"
"
"ToolStripMenuItem3
"
Me.ToolStripMenuItem3.Name = "ToolStripMenuItem3"
Me.ToolStripMenuItem3.Size = New System.Drawing.Size(152, 22)
Me.ToolStripMenuItem3.Text = "save"
"
"ToolStripMenuItem4
"
Me.ToolStripMenuItem4.Name = "ToolStripMenuItem4"
Me.ToolStripMenuItem4.Size = New System.Drawing.Size(152, 22)
Me.ToolStripMenuItem4.Text = "Quit"
"
"ToolStripMenuItem5
"
Me.ToolStripMenuItem5.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem6})
Me.ToolStripMenuItem5.Name = "ToolStripMenuItem5"
Me.ToolStripMenuItem5.Size = New System.Drawing.Size(49, 20)
Me.ToolStripMenuItem5.Text = "Edit"
"
"ToolStripMenuItem6
"
Me.ToolStripMenuItem6.Name = "ToolStripMenuItem6"
Me.ToolStripMenuItem6.Size = New System.Drawing.Size(152, 22)
Me.ToolStripMenuItem6.Text = "rename"
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(569, 275)
Me.Controls.Add(Me.MenuStrip1)
Me.IsMdiContainer = True
Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)
Me.MenuStrip1.ResumeLayout(False)
Me.MenuStrip1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents ToolStripMenuItem2 As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents ToolStripMenuItem3 As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents ToolStripMenuItem4 As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents ToolStripMenuItem5 As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents ToolStripMenuItem6 As System.Windows.Forms.ToolStripMenuItem
End Class
Public Class Form2
Private Sub Form2_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
TextBox1.Top = 5
TextBox1.Left = 5
TextBox1.Width = Me.Width - 20
TextBox1.Height = Me.Height - 45
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form2
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(12, 12)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.TextBox1.Size = New System.Drawing.Size(294, 166)
Me.TextBox1.TabIndex = 0
"
"Form2
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(318, 190)
Me.Controls.Add(Me.TextBox1)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class
Demonstrating the use of MDI parent and child windows
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class UsingMDI
public Shared Sub Main
Application.Run(New FrmUsingMDI)
End Sub
End class
Public Class FrmUsingMDI
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
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
" main menu containing menu items File and Window
Friend WithEvents mnuMain As MainMenu
" menu containing submenu New and menu item Exit
Friend WithEvents mnuitmFile As MenuItem
Friend WithEvents mnuitmExit As MenuItem
" submenu New
Friend WithEvents mnuitmNew As MenuItem
Friend WithEvents mnuitmChild1 As MenuItem
Friend WithEvents mnuitmChild2 As MenuItem
Friend WithEvents mnuitmChild3 As MenuItem
" menu containing menu items Cascade, TileHorizontal and
" TileVertical
Friend WithEvents mnuitmWindow As MenuItem
Friend WithEvents mnuitmCascade As MenuItem
Friend WithEvents mnuitmTileHorizontal As MenuItem
Friend WithEvents mnuitmTileVertical As MenuItem
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mnuitmTileHorizontal = New System.Windows.Forms.MenuItem()
Me.mnuitmTileVertical = New System.Windows.Forms.MenuItem()
Me.mnuitmChild1 = New System.Windows.Forms.MenuItem()
Me.mnuitmCascade = New System.Windows.Forms.MenuItem()
Me.mnuitmChild2 = New System.Windows.Forms.MenuItem()
Me.mnuMain = New System.Windows.Forms.MainMenu()
Me.mnuitmFile = New System.Windows.Forms.MenuItem()
Me.mnuitmNew = New System.Windows.Forms.MenuItem()
Me.mnuitmChild3 = New System.Windows.Forms.MenuItem()
Me.mnuitmExit = New System.Windows.Forms.MenuItem()
Me.mnuitmWindow = New System.Windows.Forms.MenuItem()
"
"mnuitmTileHorizontal
"
Me.mnuitmTileHorizontal.Index = 1
Me.mnuitmTileHorizontal.Text = "Tile Horizontal"
"
"mnuitmTileVertical
"
Me.mnuitmTileVertical.Index = 2
Me.mnuitmTileVertical.Text = "Tile Vertical"
"
"mnuitmChild1
"
Me.mnuitmChild1.Index = 0
Me.mnuitmChild1.Text = "Child1"
"
"mnuitmCascade
"
Me.mnuitmCascade.Index = 0
Me.mnuitmCascade.Text = "Cascade"
"
"mnuitmChild2
"
Me.mnuitmChild2.Index = 1
Me.mnuitmChild2.Text = "Child2"
"
"mnuMain
"
Me.mnuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmFile, Me.mnuitmWindow})
"
"mnuitmFile
"
Me.mnuitmFile.Index = 0
Me.mnuitmFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmNew, Me.mnuitmExit})
Me.mnuitmFile.Text = "File"
"
"mnuitmNew
"
Me.mnuitmNew.Index = 0
Me.mnuitmNew.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmChild1, Me.mnuitmChild2, Me.mnuitmChild3})
Me.mnuitmNew.Text = "New"
"
"mnuitmChild3
"
Me.mnuitmChild3.Index = 2
Me.mnuitmChild3.Text = "Child3"
"
"mnuitmExit
"
Me.mnuitmExit.Index = 1
Me.mnuitmExit.Text = "Exit"
"
"mnuitmWindow
"
Me.mnuitmWindow.Index = 1
Me.mnuitmWindow.MdiList = True
Me.mnuitmWindow.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmCascade, Me.mnuitmTileHorizontal, Me.mnuitmTileVertical})
Me.mnuitmWindow.Text = "Window"
"
"FrmUsingMDI
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 301)
Me.IsMdiContainer = True
Me.Menu = Me.mnuMain
Me.Name = "FrmUsingMDI"
Me.Text = "UsingMDI"
End Sub
#End Region
Private childWindow As FrmChild
Private Sub mnuitmChild1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmChild1.Click
childWindow = New FrmChild("Child1")
childWindow.MdiParent = Me
childWindow.Show()
End Sub
Private Sub mnuitmChild2_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmChild2.Click
childWindow = New FrmChild("Child2")
childWindow.MdiParent = Me
childWindow.Show()
End Sub
Private Sub mnuitmChild3_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmChild3.Click
childWindow = New FrmChild("Child3")
childWindow.MdiParent = Me
childWindow.Show()
End Sub
Private Sub mnuitmExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmExit.Click
Application.Exit()
End Sub
Private Sub mnuitmCascade_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmCascade.Click
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
Private Sub mnuitmTileHorizontal_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles mnuitmTileHorizontal.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub
Private Sub mnuitmTileVertical_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmTileVertical.Click
Me.LayoutMdi(MdiLayout.TileVertical)
End Sub
End Class
Public Class FrmChild
Inherits Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
" Public Sub New(ByVal imageInformation As String, ByVal windowName As String)
" Display(imageInformation, windowName)
" End Sub
"Form overrides dispose to clean up the component list.
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
" contains an image loaded from disk
Friend WithEvents picDisplay As PictureBox
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.picDisplay = New System.Windows.Forms.PictureBox()
Me.SuspendLayout()
"
"picDisplay
"
Me.picDisplay.Location = New System.Drawing.Point(8, 8)
Me.picDisplay.Name = "picDisplay"
Me.picDisplay.Size = New System.Drawing.Size(256, 208)
Me.picDisplay.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
Me.picDisplay.TabIndex = 0
Me.picDisplay.TabStop = False
"
"FrmChild1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(272, 221)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.picDisplay})
Me.Name = "FrmChild"
Me.Text = ""
Me.ResumeLayout(False)
End Sub
#End Region
Public Sub New( ByVal name As String)
Me.New()
Me.Text = name
picDisplay.Image = Image.FromFile("YourFile.bmp")
End Sub " New
End Class
MDI Children Form Array
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MDIChildrenFormArray
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
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
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.IsMdiContainer = True
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Forms(4) As Form2
For i As Integer = 0 To 4
Forms(i) = New Form2
Forms(i).Text = "Document" & Str(i)
Forms(i).MdiParent = Me
Forms(i).Show()
Next i
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
End Class
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
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
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.TextBox1.Location = New System.Drawing.Point(0, 0)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(292, 273)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
"
"Form2
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class OpenChildrenFormInMenuAction
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
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
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
"
"MainMenu1
"
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem3})
"
"MenuItem1
"
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})
Me.MenuItem1.Text = "File"
"
"MenuItem2
"
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "New..."
"
"MenuItem3
"
Me.MenuItem3.Index = 1
Me.MenuItem3.MdiList = True
Me.MenuItem3.Text = "Window"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Dim frmForm As Form2
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
frmForm = New Form2
frmForm.Text = "New Document"
frmForm.MdiParent = Me
frmForm.Show()
End Sub
End Class
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
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
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.TextBox1.Location = New System.Drawing.Point(0, 0)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(184, 149)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
"
"MainMenu1
"
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
"
"MenuItem1
"
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})
Me.MenuItem1.Text = "Edit"
"
"MenuItem2
"
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "Auto Format"
"
"Form2
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(184, 149)
Me.Controls.Add(Me.TextBox1)
Me.Menu = Me.MainMenu1
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
RichText MDI Editor
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
public class MDIRichTextBoxEditor
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form2
Inherits System.Windows.Forms.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.ruponentModel.IContainer
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.SuspendLayout()
"
"Label1
"
Me.Label1.Location = New System.Drawing.Point(144, 201)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 15)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Label1"
"
"ProgressBar1
"
Me.ProgressBar1.Location = New System.Drawing.Point(48, 224)
Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.Size = New System.Drawing.Size(280, 24)
Me.ProgressBar1.TabIndex = 2
"
"RichTextBox1
"
Me.RichTextBox1.Location = New System.Drawing.Point(32, 24)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(400, 224)
Me.RichTextBox1.TabIndex = 3
Me.RichTextBox1.Text = "RichTextBox1"
"
"Form2
"
Me.AutoScaleBaseSize = New System.Drawing.Size(8, 18)
Me.ClientSize = New System.Drawing.Size(475, 272)
Me.Controls.Add(Me.RichTextBox1)
Me.Controls.Add(Me.ProgressBar1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
RichTextBox1.Left = 0
RichTextBox1.Top = 0
RichTextBox1.Width = Me.ClientSize.Width
RichTextBox1.Height = Me.ClientSize.Height
End Sub
Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
End Sub
Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
" If Form1.DocNum > 1 Then
" Form1.docnum = Form1.docnum - 1
" Else : Form1.docnum = 0
" End If
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
Dim frmSplash As New Form2()
frmSplash.Show()
Dim i, j As Int64
For i = 1 To 100
For j = 1 To 1000000
Next
frmSplash.RichTextBox1.Visible = False
frmSplash.Label1.Text = CStr(i)
frmSplash.ProgressBar1.Value = i
frmSplash.Refresh()
Next
frmSplash.Close()
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.ruponentModel.IContainer
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem10 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem12 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem13 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem15 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem16 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem17 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem18 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem19 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem20 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem21 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem22 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem23 As System.Windows.Forms.MenuItem
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ruponents = New System.ruponentModel.Container
Me.MainMenu1 = New System.Windows.Forms.MainMenu(Me.ruponents)
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.MenuItem10 = New System.Windows.Forms.MenuItem
Me.MenuItem11 = New System.Windows.Forms.MenuItem
Me.MenuItem12 = New System.Windows.Forms.MenuItem
Me.MenuItem13 = New System.Windows.Forms.MenuItem
Me.MenuItem14 = New System.Windows.Forms.MenuItem
Me.MenuItem15 = New System.Windows.Forms.MenuItem
Me.MenuItem16 = New System.Windows.Forms.MenuItem
Me.MenuItem17 = New System.Windows.Forms.MenuItem
Me.MenuItem18 = New System.Windows.Forms.MenuItem
Me.MenuItem19 = New System.Windows.Forms.MenuItem
Me.MenuItem20 = New System.Windows.Forms.MenuItem
Me.MenuItem21 = New System.Windows.Forms.MenuItem
Me.MenuItem22 = New System.Windows.Forms.MenuItem
Me.MenuItem23 = New System.Windows.Forms.MenuItem
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
Me.SuspendLayout()
"
"MainMenu1
"
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem9, Me.MenuItem17, Me.MenuItem23})
"
"MenuItem1
"
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem6, Me.MenuItem7, Me.MenuItem8})
Me.MenuItem1.Text = "File"
"
"MenuItem2
"
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "New"
"
"MenuItem3
"
Me.MenuItem3.Index = 1
Me.MenuItem3.Text = "Open"
"
"MenuItem4
"
Me.MenuItem4.Index = 2
Me.MenuItem4.Text = "Close"
"
"MenuItem6
"
Me.MenuItem6.Index = 3
Me.MenuItem6.Text = "Save as"
"
"MenuItem7
"
Me.MenuItem7.Index = 4
Me.MenuItem7.Text = "-"
"
"MenuItem8
"
Me.MenuItem8.Index = 5
Me.MenuItem8.Text = "Quit"
"
"MenuItem9
"
Me.MenuItem9.Index = 1
Me.MenuItem9.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem10, Me.MenuItem11, Me.MenuItem12, Me.MenuItem13, Me.MenuItem14, Me.MenuItem15, Me.MenuItem16})
Me.MenuItem9.Text = "Edit"
"
"MenuItem10
"
Me.MenuItem10.Index = 0
Me.MenuItem10.Text = "Restore"
"
"MenuItem11
"
Me.MenuItem11.Index = 1
Me.MenuItem11.Text = "Select all"
"
"MenuItem12
"
Me.MenuItem12.Index = 2
Me.MenuItem12.Text = "-"
"
"MenuItem13
"
Me.MenuItem13.Index = 3
Me.MenuItem13.Text = "Cut"
"
"MenuItem14
"
Me.MenuItem14.Index = 4
Me.MenuItem14.Text = "Copy"
"
"MenuItem15
"
Me.MenuItem15.Index = 5
Me.MenuItem15.Text = "Pastr"
"
"MenuItem16
"
Me.MenuItem16.Index = 6
Me.MenuItem16.Text = "Cut"
"
"MenuItem17
"
Me.MenuItem17.Index = 2
Me.MenuItem17.MdiList = True
Me.MenuItem17.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem18, Me.MenuItem19, Me.MenuItem20, Me.MenuItem21, Me.MenuItem22})
Me.MenuItem17.Text = "Window"
"
"MenuItem18
"
Me.MenuItem18.Index = 0
Me.MenuItem18.Text = "Cascade"
"
"MenuItem19
"
Me.MenuItem19.Index = 1
Me.MenuItem19.Text = "Horizontal"
"
"MenuItem20
"
Me.MenuItem20.Index = 2
Me.MenuItem20.Text = "Virtical"
"
"MenuItem21
"
Me.MenuItem21.Index = 3
Me.MenuItem21.Text = "Arrange Icon"
"
"MenuItem22
"
Me.MenuItem22.Index = 4
Me.MenuItem22.Text = "About"
"
"MenuItem23
"
Me.MenuItem23.Index = 3
Me.MenuItem23.Text = ""
"
"SaveFileDialog1
"
Me.SaveFileDialog1.FileName = "doc1"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(8, 18)
Me.ClientSize = New System.Drawing.Size(428, 187)
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Public docnum As Integer
Private Sub MenuItem18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem18.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade)
End Sub
Private Sub MenuItem22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem22.Click
Dim formabout As New Form2()
formabout.ProgressBar1.Visible = False
formabout.RichTextBox1.Visible = False
formabout.Label1.Text = "Welcome"
formabout.ShowDialog()
formabout.Dispose()
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim NewMDIChild As New Form2()
docnum = docnum + 1
NewMDIChild.Text = "MDI " & docnum
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
Dim activechild As Form = Me.ActiveMdiChild
If (Not activechild Is Nothing) Then
activechild.Close()
End If
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim fileName As String
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.FilterIndex = 2
OpenFileDialog1.RestoreDirectory = True
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
fileName = OpenFileDialog1.FileName
End If
If fileName = "" Then Exit Sub
Dim NewMDIChild As New Form2()
docnum = docnum + 1
NewMDIChild.MdiParent = Me
NewMDIChild.Text = fileName
NewMDIChild.RichTextBox1.LoadFile(fileName, RichTextBoxStreamType.PlainText)
NewMDIChild.Show()
End Sub
Private Sub MenuItem19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem19.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.TileHorizontal)
End Sub
Private Sub MenuItem20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem20.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.TileVertical)
End Sub
Private Sub MenuItem21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem21.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.ArrangeIcons)
End Sub
Private Sub MenuItem14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem14.Click
Dim activechild As Form = Me.ActiveMdiChild
If (Not activechild Is Nothing) Then
Try
Dim theBox As RichTextBox
theBox = CType(activechild.ActiveControl, RichTextBox)
If (Not theBox Is Nothing) Then
Clipboard.SetDataObject(theBox.SelectedText)
End If
Catch
MessageBox.Show("No selected RichTextBox")
End Try
End If
End Sub
Private Sub MenuItem15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem15.Click
Dim activeChild As Form
activeChild = Me.ActiveMdiChild
If (Not activeChild Is Nothing) Then
Try
Dim theBox As RichTextBox
theBox = CType(activeChild.ActiveControl, RichTextBox)
If (Not theBox Is Nothing) Then
Dim data As IDataObject
data = Clipboard.GetDataObject()
If (data.GetDataPresent(DataFormats.Text)) Then
theBox.SelectedText = data.GetData(DataFormats.Text).ToString()
End If
End If
Catch
MessageBox.Show("NO RichTextBox selected")
End Try
End If
End Sub
Private Sub MenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem13.Click
Dim activechild As Form = Me.ActiveMdiChild
If (Not activechild Is Nothing) Then
Try
Dim theBox As RichTextBox
theBox = CType(activechild.ActiveControl, RichTextBox)
If (Not theBox Is Nothing) Then
Clipboard.SetDataObject(theBox.SelectedText)
theBox.SelectedText = ""
End If
Catch
MessageBox.Show("No RichTextBox selected ")
End Try
End If
End Sub
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
Dim fileName As String
SaveFileDialog1.InitialDirectory = "c:\"
SaveFileDialog1.DefaultExt = "*.txt"
SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.RestoreDirectory = True
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
fileName = SaveFileDialog1.FileName
End If
If fileName = "" Then Exit Sub
Dim activeChild As Form
activeChild = Me.ActiveMdiChild
If (Not activeChild Is Nothing) Then
Try
Dim theBox As RichTextBox
theBox = CType(activeChild.ActiveControl, RichTextBox)
If (Not theBox Is Nothing) Then
theBox.SaveFile(fileName, RichTextBoxStreamType.PlainText)
End If
Catch
MessageBox.Show("No RichTextBox selected ")
End Try
End If
End Sub
Private Sub MenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem11.Click
Dim activechild As Form = Me.ActiveMdiChild
If (Not activechild Is Nothing) Then
Try
Dim theBox As RichTextBox
theBox = CType(activechild.ActiveControl, RichTextBox)
If (Not theBox Is Nothing) Then
theBox.SelectAll()
End If
Catch
MessageBox.Show("No RichTextBox selected ")
End Try
End If
End Sub
Private Sub MenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem10.Click
Dim activechild As Form = Me.ActiveMdiChild
If (Not activechild Is Nothing) Then
Try
Dim theBox As RichTextBox
theBox = CType(activechild.ActiveControl, RichTextBox)
If (Not theBox Is Nothing) Then
theBox.Undo()
End If
Catch
MessageBox.Show("No RichTextBox selected ")
End Try
End If
End Sub
Private Sub MenuItem16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem16.Click
Dim activechild As Form = Me.ActiveMdiChild
If (Not activechild Is Nothing) Then
Try
Dim theBox As RichTextBox
theBox = CType(activechild.ActiveControl, RichTextBox)
If (Not theBox Is Nothing) Then
theBox.SelectedText = ""
End If
Catch
MessageBox.Show("No RichTextBox selected")
End Try
End If
End Sub
Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
Close()
End Sub
End Class
Use a tree to manage MDI Child window
Imports System.Windows.Forms
public class ParentFormMDI
public Shared Sub Main
Application.Run(New ParentForm)
End Sub
End class
Public Class ParentForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
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
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents cmdCascade As System.Windows.Forms.MenuItem
Friend WithEvents menuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents menuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents cmdWindowArrangeIcons As System.Windows.Forms.MenuItem
Friend WithEvents cmdWindowTileChildrenVert As System.Windows.Forms.MenuItem
Friend WithEvents cmdWindowTileChildrenHoriz As System.Windows.Forms.MenuItem
Friend WithEvents menuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents statusBar1 As System.Windows.Forms.StatusBar
Friend WithEvents cmdFileNewChild As System.Windows.Forms.MenuItem
Friend WithEvents cmdFileExit As System.Windows.Forms.MenuItem
Friend WithEvents treeView1 As System.Windows.Forms.TreeView
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents menuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents splitter1 As System.Windows.Forms.Splitter
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.cmdCascade = New System.Windows.Forms.MenuItem()
Me.menuItem7 = New System.Windows.Forms.MenuItem()
Me.menuItem3 = New System.Windows.Forms.MenuItem()
Me.cmdWindowArrangeIcons = New System.Windows.Forms.MenuItem()
Me.cmdWindowTileChildrenVert = New System.Windows.Forms.MenuItem()
Me.cmdWindowTileChildrenHoriz = New System.Windows.Forms.MenuItem()
Me.menuItem8 = New System.Windows.Forms.MenuItem()
Me.statusBar1 = New System.Windows.Forms.StatusBar()
Me.cmdFileNewChild = New System.Windows.Forms.MenuItem()
Me.cmdFileExit = New System.Windows.Forms.MenuItem()
Me.treeView1 = New System.Windows.Forms.TreeView()
Me.mainMenu1 = New System.Windows.Forms.MainMenu()
Me.menuItem1 = New System.Windows.Forms.MenuItem()
Me.menuItem9 = New System.Windows.Forms.MenuItem()
Me.splitter1 = New System.Windows.Forms.Splitter()
Me.SuspendLayout()
"
"cmdCascade
"
Me.cmdCascade.Index = 1
Me.cmdCascade.Text = "&Cascade"
"
"menuItem7
"
Me.menuItem7.Index = 4
Me.menuItem7.Text = "-"
"
"menuItem3
"
Me.menuItem3.Index = 1
Me.menuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmdWindowArrangeIcons, Me.cmdCascade, Me.cmdWindowTileChildrenVert, Me.cmdWindowTileChildrenHoriz, Me.menuItem7, Me.menuItem8})
Me.menuItem3.MergeOrder = 2
Me.menuItem3.Text = "&Window"
"
"cmdWindowArrangeIcons
"
Me.cmdWindowArrangeIcons.Index = 0
Me.cmdWindowArrangeIcons.Text = "&Arrange Icons"
"
"cmdWindowTileChildrenVert
"
Me.cmdWindowTileChildrenVert.Index = 2
Me.cmdWindowTileChildrenVert.Text = "Tile Children &Vertically"
"
"cmdWindowTileChildrenHoriz
"
Me.cmdWindowTileChildrenHoriz.Index = 3
Me.cmdWindowTileChildrenHoriz.Text = "Tile Children &Horizontally"
"
"menuItem8
"
Me.menuItem8.Index = 5
Me.menuItem8.MdiList = True
Me.menuItem8.Text = "Window&s"
"
"statusBar1
"
Me.statusBar1.Location = New System.Drawing.Point(0, 179)
Me.statusBar1.Name = "statusBar1"
Me.statusBar1.Size = New System.Drawing.Size(352, 22)
Me.statusBar1.TabIndex = 4
Me.statusBar1.Text = "Ready"
"
"cmdFileNewChild
"
Me.cmdFileNewChild.Index = 0
Me.cmdFileNewChild.Shortcut = System.Windows.Forms.Shortcut.CtrlN
Me.cmdFileNewChild.Text = "&New Child"
"
"cmdFileExit
"
Me.cmdFileExit.Index = 2
Me.cmdFileExit.MergeOrder = 2
Me.cmdFileExit.Text = "E&xit"
"
"treeView1
"
Me.treeView1.Dock = System.Windows.Forms.DockStyle.Left
Me.treeView1.ImageIndex = -1
Me.treeView1.Location = New System.Drawing.Point(3, 0)
Me.treeView1.Name = "treeView1"
Me.treeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Children")})
Me.treeView1.SelectedImageIndex = -1
Me.treeView1.Size = New System.Drawing.Size(121, 179)
Me.treeView1.TabIndex = 5
"
"mainMenu1
"
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.menuItem3})
"
"menuItem1
"
Me.menuItem1.Index = 0
Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmdFileNewChild, Me.menuItem9, Me.cmdFileExit})
Me.menuItem1.MergeType = System.Windows.Forms.MenuMerge.MergeItems
Me.menuItem1.Text = "&File"
"
"menuItem9
"
Me.menuItem9.Index = 1
Me.menuItem9.MergeOrder = 2
Me.menuItem9.Text = "-"
"
"splitter1
"
Me.splitter1.Name = "splitter1"
Me.splitter1.Size = New System.Drawing.Size(3, 179)
Me.splitter1.TabIndex = 6
Me.splitter1.TabStop = False
"
"ParentForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(352, 201)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.treeView1, Me.splitter1, Me.statusBar1})
Me.IsMdiContainer = True
Me.Menu = Me.mainMenu1
Me.Name = "ParentForm"
Me.Text = "MDI Parent"
Me.ResumeLayout(False)
End Sub
#End Region
Dim nextChild As Integer = 1
Public Sub ChildClosed(ByVal sender As Object, ByVal e As EventArgs)
Dim node As TreeNode
For Each node In treeView1.Nodes(0).Nodes
If node.Tag Is sender Then
treeView1.Nodes(0).Nodes.Remove(node)
Exit For
End If
Next
End Sub
Private Sub cmdFileNewChild_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFileNewChild.Click
Dim child As Form = New ChildForm()
child.Text = "Child " & nextChild.ToString()
AddHandler child.Closed, AddressOf ChildClosed
nextChild = nextChild + 1
child.MdiParent = Me
child.Show()
Dim node As TreeNode = New TreeNode(child.Text)
node.Tag = child
treeView1.Nodes(0).Nodes.Add(node)
treeView1.Nodes(0).Expand()
End Sub
Private Sub cmdFileExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFileExit.Click
Close()
End Sub
Private Sub treeView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles treeView1.Click
Dim child As Form
If TypeOf (treeView1.SelectedNode.Tag) Is Form Then
child = CType(treeView1.SelectedNode.Tag, Form)
End If
If Not child Is Nothing Then child.Activate()
End Sub
End Class
Public Class ChildForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
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
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents menuItem11 As System.Windows.Forms.MenuItem
Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents cmdFileClose As System.Windows.Forms.MenuItem
Friend WithEvents menuItem13 As System.Windows.Forms.MenuItem
Friend WithEvents menuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents menuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents menuItem6 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mainMenu1 = New System.Windows.Forms.MainMenu()
Me.menuItem11 = New System.Windows.Forms.MenuItem()
Me.menuItem1 = New System.Windows.Forms.MenuItem()
Me.cmdFileClose = New System.Windows.Forms.MenuItem()
Me.menuItem13 = New System.Windows.Forms.MenuItem()
Me.menuItem5 = New System.Windows.Forms.MenuItem()
Me.menuItem4 = New System.Windows.Forms.MenuItem()
Me.menuItem6 = New System.Windows.Forms.MenuItem()
"
"mainMenu1
"
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem11, Me.menuItem13})
"
"menuItem11
"
Me.menuItem11.Index = 0
Me.menuItem11.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.cmdFileClose})
Me.menuItem11.MergeType = System.Windows.Forms.MenuMerge.MergeItems
Me.menuItem11.Text = "&File"
"
"menuItem1
"
Me.menuItem1.Index = 0
Me.menuItem1.MergeOrder = 1
Me.menuItem1.Text = "&Save"
"
"cmdFileClose
"
Me.cmdFileClose.Index = 1
Me.cmdFileClose.MergeOrder = 1
Me.cmdFileClose.Text = "&Close"
"
"menuItem13
"
Me.menuItem13.Index = 1
Me.menuItem13.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem5, Me.menuItem4, Me.menuItem6})
Me.menuItem13.MergeOrder = 1
Me.menuItem13.Text = "&Edit"
"
"menuItem5
"
Me.menuItem5.Index = 0
Me.menuItem5.Text = "Cu&t"
"
"menuItem4
"
Me.menuItem4.Index = 1
Me.menuItem4.Text = "&Copy"
"
"menuItem6
"
Me.menuItem6.Index = 2
Me.menuItem6.Text = "&Paste"
"
"ChildForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(168, 147)
Me.Menu = Me.mainMenu1
Me.Name = "ChildForm"
Me.Text = "MDI Child"
End Sub
#End Region
Private Sub cmdFileClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFileClose.Click
Close()
End Sub
End Class