Single Document Interface (SDI) Demo
Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.IO
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim myform As Form = New Form1()
Application.Run(myform)
End Sub
End Class
Public Class Form1
Private m_FileLoaded As Boolean = False
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
If dlgOpen.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim frm As Form1
If m_FileLoaded Then
frm = New Form1
Else
frm = Me
End If
frm.txtContents.Text = File.ReadAllText(dlgOpen.FileName)
frm.Text = "# [" & New FileInfo(dlgOpen.FileName).Name & "]"
frm.m_FileLoaded = True
frm.Show()
End If
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Public 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.ComponentModel.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.FileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
Me.mnuOpen = New System.Windows.Forms.ToolStripMenuItem
Me.dlgOpen = New System.Windows.Forms.OpenFileDialog
Me.txtContents = New System.Windows.Forms.TextBox
Me.MenuStrip1.SuspendLayout()
Me.SuspendLayout()
'
'MenuStrip1
'
Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem})
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
Me.MenuStrip1.Name = "MenuStrip1"
Me.MenuStrip1.Size = New System.Drawing.Size(292, 24)
Me.MenuStrip1.TabIndex = 9
Me.MenuStrip1.Text = "MenuStrip1"
'
'FileToolStripMenuItem
'
Me.FileToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuOpen})
Me.FileToolStripMenuItem.Name = "FileToolStripMenuItem"
Me.FileToolStripMenuItem.Size = New System.Drawing.Size(44, 20)
Me.FileToolStripMenuItem.Text = "&File"
'
'mnuOpen
'
Me.mnuOpen.Name = "mnuOpen"
Me.mnuOpen.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.O), System.Windows.Forms.Keys)
Me.mnuOpen.Size = New System.Drawing.Size(168, 22)
Me.mnuOpen.Text = "&Open"
'
'txtContents
'
Me.txtContents.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.txtContents.Location = New System.Drawing.Point(0, 24)
Me.txtContents.Multiline = True
Me.txtContents.Name = "txtContents"
Me.txtContents.Size = New System.Drawing.Size(292, 249)
Me.txtContents.TabIndex = 8
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.txtContents)
Me.Controls.Add(Me.MenuStrip1)
Me.Name = "Form1"
Me.Text = "SdiEdit []"
Me.MenuStrip1.ResumeLayout(False)
Me.MenuStrip1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
Friend WithEvents FileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents mnuOpen As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents dlgOpen As System.Windows.Forms.OpenFileDialog
Friend WithEvents txtContents As System.Windows.Forms.TextBox
End Class
Related examples in the same category