Create Notepad Application Using Rich Text Box Control in VB

Step by step Procedure Algorithm: notepad has been created Using Rich text box control in Visual Programming tool . Form1.Caption = "Untitled - Notepad" this command whenever you open the new notepad in there title is display as "Untitled - Notepad". Whenever you save the edit notepad file file.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*" file.InitDir = "c:\" this command indicate save file as .txt extension and save file directory in c: , there notepad font indicate by following command file.ShowFont, Text1.FontName = file.FontName, Text1.FontBold = file.FontBold, Text1.FontItalic = file.FontItalic, Text1.FontSize = file.FontSize.
Output notepad application rich text box control in Visual programming
notepad application using rich text box control in VBSource CODE Visual Programming Lap
Dim fn As String
Dim ul As Boolean
Dim st As Boolean
Dim m As Integer
Private Sub Form_Load()
m = 0
ul = False
st = False
End Sub
Private Sub Form_Resize()
If WindowState = 1 Then
Exit Sub
End If
Text1.Width = ScaleWidth
Text1.Height = ScaleHeight
End Sub

Private Sub Form_Unload(Cancel As Integer)
mnufileexit_Click
End Sub


Private Sub mnufilenew_Click()
If Text1 <> "" Then
msg = "The Text in the file has changed." & vbCrLf & "Do u wish to save the changes?"
res = MsgBox(msg, vbYesNoCancel, "Save File?")
Select Case res
Case vbYes
If fn = "" Then
mnufilesaveas_Click
Else
mnufilesave_Click
End If
Text1 = ""
Form1.Caption = "Untitled - Notepad"
Case vbNo
Text1 = ""
Form1.Caption = "Untitled - Notepad"
Case vbCancel
End Select
End If
End Sub

Private Sub mnufileopen_Click()
file.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
file.InitDir = "c:\"
file.ShowOpen

If file.FileName = "" Then
Exit Sub
End If
fn = file.FileName
Open fn For Input As #1
Text1.Text = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
Form1.Caption = file.FileTitle & " - Notepad"
End Sub

Private Sub mnufilesave_Click()
On Error GoTo errhandler
file.CancelError = True
file.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
file.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
If fn = "" Then
file.FileName = ""
file.ShowSave
fn = file.FileName
End If
Open fn For Output As #1
Print #1, Text1.Text
Close #1
Form1.Caption = file.FileTitle & " - Notepad"
errhandler:
Select Case Err
Case 32755 ' Dialog Cancelled
End Select
End Sub

Private Sub mnufilesaveas_Click()
On Error GoTo errhandler
file.CancelError = True
file.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
file.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
file.FileName = fn
file.ShowSave
fn = file.FileName
Open fn For Output As #1
Print #1, Text1.Text
Close #1
Form1.Caption = file.FileTitle & " - Notepad"
errhandler:
Select Case Err
Case 32755 ' Dialog Cancelled
End Select
End Sub

Private Sub mnufileexit_Click()
If Text1 <> "" Then
msg = "The Text in the file has changed." & vbCrLf & "Do u wish to save the changes?"
res = MsgBox(msg, vbExclamation + vbYesNoCancel, "Save File?")
Select Case res
Case vbYes
If fn = "" Then
mnufilesaveas_Click
Else
mnufilesave_Click
End If
End
Case vbNo
End
Case vbCancel
End Select
Else
End
End If
End Sub

Private Sub mnueditcut_Click()
If m = 1 Then

Clipboard.SetText Text1.Text
Text1.Text = ""
Else

Clipboard.SetText Text1.SelText
Text1.SelText = ""
End If

End Sub

Private Sub mnueditcopy_Click()
If m = 1 Then
Clipboard.SetText Text1.Text
Else

Clipboard.SetText Text1.SelText
End If

End Sub

Private Sub mnueditpaste_Click()
Text1.SelText = Clipboard.GetText
End Sub

Private Sub mnufont_Click()
On Error GoTo errhandler
file.Flags = cdlCFScreenFonts Or cdlCFPrinterFonts
file.ShowFont
Text1.FontName = file.FontName
Text1.FontBold = file.FontBold
Text1.FontItalic = file.FontItalic
Text1.FontSize = file.FontSize
errhandler:
Select Case Err
Case 32755 ' Dialog Cancelled
End Select
End Sub

Private Sub mnueditbc_Click()
On Error GoTo errhandler
file.CancelError = True
file.ShowColor
Text1.BackColor = file.Color
errhandler:
Select Case Err
Case 32755 ' Dialog Cancelled
End Select
End Sub

Private Sub mnueditfc_Click()
On Error GoTo errhandler
file.CancelError = True
file.ShowColor
Text1.ForeColor = file.Color
errhandler:
Select Case Err
Case 32755 ' Dialog Cancelled
End Select
End Sub


Private Sub mnuabt_Click()
MsgBox ("THIS IS NOTEPAD")
End Sub

Private Sub mnufontst_Click()
st = Not st
Text1.FontStrikethru = st
End Sub

Private Sub mnufontul_Click()
ul = Not ul
Text1.FontUnderline = ul
End Sub

Private Sub selectall_Click()
Text1.ForeColor = green
m = 1
End Sub



Related post