Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.multiline = True
TextBox1.Clear()
Me.Text = "Простой текстовый редактор"
OpenFileDialog1.FileName = Nothing
OpenFileDialog1.Filter = "Текстовые файлы (*.txt) |'.txt|A11 files (*.*)|*.*"
SaveFileDialog1.Filter = "Текстовые файлы (f.txt) |*.txt|A11 files (*.*)|*.*"
End Sub
Private Sub ФайлToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ФайлToolStripMenuItem.Click
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName = Nothing Then Exit Sub
Try
Dim Читатель As New IO.StreamReader(OpenFileDialog1.FileName, System.Text.Encoding.GetEncoding(1251))
Читатель.Close()
Catch Exc As System.IO.FileNotFoundException
MessageBox.Show("Нет такого файла", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch Exc As Exception
MessageBox.Show(Exc.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub
Private Sub СохранитьКакToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles СохранитьКакToolStripMenuItem.Click
SaveFileDialog1.FileName = SaveFileDialog1.FileName
If SaveFileDialog1.ShowDialog = DialogResult.OK Then Запись()
End Sub
Sub Запись()
Try
Dim Писатель As New IO.StreamWriter(SaveFileDialog1.FileName, False, System.Text.Encoding.GetEncoding(1251))
Писатель.Write(TextBox1.Text)
Писатель.Close()
TextBox1.Modified = False
Catch Exc As Exception
MessageBox.Show(Exc.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub
Private Sub ВыходToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ВыходToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub Form1_Closeing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If TextBox1.Modified - False Then Exit Sub
Dim MBox As DialogResult
MessageBox.Show("Текст был изменен." & vbCrLf & "Сохранить изменения?", "Простой редактор", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation)
If MBox = DialogResult.No Then Exit Sub
If MBox = DialogResult.Cancel Then e.Cancel = True
If MBox = DialogResult.Yes Then
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
Запись() : Exit Sub
Else
e.Cancel = True
End If
End If
End Sub
Private Sub ВставитьToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ВставитьToolStripMenuItem.Click
Clipboard.Clear()
Clipboard.SetText(RichTextBox1.SelectedText)
RichTextBox1.SelectedText = Clipboard.GetText()
End Sub
Private Sub ШрифтToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ШрифтToolStripMenuItem.Click
FontDialog1.ShowColor = True
FontDialog1.ShowDialog()
RichTextBox1.SelectionFont = FontDialog1.Font
RichTextBox1.SelectionColor = FontDialog1.Color
End Sub
Private Function FontDialog1() As Object
Throw New NotImplementedException
End Function