0% found this document useful (0 votes)
22 views

Notepad Code

The document describes the functionality of a basic text editor program. It includes code snippets for common text editing functions like opening, saving, and creating new files. It also includes code to implement standard editing tools such as undo, cut, copy, paste, font selection, text alignment, and background color selection. The code checks for changes before saving and prompts the user to confirm overwriting existing files.

Uploaded by

OFFICIAL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Notepad Code

The document describes the functionality of a basic text editor program. It includes code snippets for common text editing functions like opening, saving, and creating new files. It also includes code to implement standard editing tools such as undo, cut, copy, paste, font selection, text alignment, and background color selection. The code checks for changes before saving and prompts the user to confirm overwriting existing files.

Uploaded by

OFFICIAL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Text files (*.

txt)|

File New
'Check if there's text added to the textbox
If TextBox1.Modified Then
'If the text of notepad changed, the program will ask the user if they want to
save the changes
Dim ask As MsgBoxResult
ask = MsgBox("Do you want to save the changes", MsgBoxStyle.YesNoCancel, "New
Document")
If ask = MsgBoxResult.No Then
TextBox1.Clear()
ElseIf ask = MsgBoxResult.Cancel Then
ElseIf ask = MsgBoxResult.Yes Then
SaveFileDialog1.ShowDialog()
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text,
False)
TextBox1.Clear()
End If
'If textbox's text is still the same, notepad will open a new page:
Else
TextBox1.Clear()
End If

File Open
'Check if there's text added to the textbox
If TextBox1.Modified Then
'If the text of notepad changed, the program will ask the user if they want to
save the changes
Dim ask As MsgBoxResult
ask = MsgBox("Do you want to save the changes", MsgBoxStyle.YesNoCancel, "Open
Document")
If ask = MsgBoxResult.No Then
OpenFileDialog1.ShowDialog()
TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
ElseIf ask = MsgBoxResult.Cancel Then
ElseIf ask = MsgBoxResult.Yes Then
SaveFileDialog1.ShowDialog()
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text,
False)
TextBox1.Clear()
End If
Else
'If textbox's text is still the same, notepad will show the OpenFileDialog
OpenFileDialog1.ShowDialog()
Try
TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
Catch ex As Exception
End Try
End If
File Save
SaveFileDialog1.ShowDialog()
' the application will check if the file is already exists, if exists, it will
ask the user if they want to replace it
If My.Computer.FileSystem.FileExists(SaveFileDialog1.FileName) Then
Dim ask As MsgBoxResult
ask = MsgBox("File already exists, would you like to replace it?",
MsgBoxStyle.YesNo, "File Exists")
'if the user decides not to replace the existing file
If ask = MsgBoxResult.No Then
SaveFileDialog1.ShowDialog()
'if the user decides to replace the existing file
ElseIf ask = MsgBoxResult.Yes Then
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text,
False)
End If
'if the file doesn't exist
Else
Try
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text,
False)
Catch ex As Exception
End Try
End If

File Exit
End

Undo
'check if textbox can undo
If TextBox1.CanUndo Then
TextBox1.Undo()
Else
End If

Cut
My.Computer.Clipboard.Clear()
If TextBox1.SelectionLength > 0 Then
My.Computer.Clipboard.SetText(TextBox1.SelectedText)

End If
TextBox1.SelectedText = ""

Copy
My.Computer.Clipboard.Clear()
If TextBox1.SelectionLength > 0 Then
My.Computer.Clipboard.SetText(TextBox1.SelectedText)

End If

Paste
If My.Computer.Clipboard.ContainsText Then
TextBox1.Paste()
End If

Select All
TextBox1.SelectAll()

Find
Dim a As String
Dim b As String
a = InputBox("Enter text to be found")
b = InStr(TextBox1.Text, a)
If b Then
TextBox1.Focus()
TextBox1.SelectionStart = b - 1
TextBox1.SelectionLength = Len(a)
Else
MsgBox("Text not found.")
End If

Format Font
FontDialog1.ShowDialog()
TextBox1.Font = FontDialog1.Font

Font Color
ColorDialog1.ShowDialog()
TextBox1.ForeColor = ColorDialog1.Color

Align Left
TextBox1.TextAlign = HorizontalAlignment.Left
LeftToolStripMenuItem.Checked = True
CenterToolStripMenuItem.Checked = False
RightToolStripMenuItem.Checked = False
Center
TextBox1.TextAlign = HorizontalAlignment.Center
LeftToolStripMenuItem.Checked = False
CenterToolStripMenuItem.Checked = True
RightToolStripMenuItem.Checked = False

Right
TextBox1.TextAlign = HorizontalAlignment.Right
LeftToolStripMenuItem.Checked = False
CenterToolStripMenuItem.Checked = False
RightToolStripMenuItem.Checked = True

Background Color
ColorDialog1.ShowDialog()
TextBox1.BackColor = ColorDialog1.Color

You might also like