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.ComponentModel.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.ComponentModel.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.components = New System.ComponentModel.Container
Me.MainMenu1 = New System.Windows.Forms.MainMenu(Me.components)
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
|