RTF document editor
Posted: Fri Aug 21, 2009 1:23 am
Hello,
I was just going through my project folder and found this document editor I was working on some time ago. Its only basic but may help you if you want to make a text editor.
![Image]()
Features include:
Save & Load as *.rtf file (saves font/sizes/colour etc rather than just plain text)
Change text colour
Change text font/size
Change font style
Here is how to make this little application. First you will need to add the following controls to your form:
MenuStrip - add 3 fields into this control "Save"..."Load"...and "Exit"
14 Buttons
1 RichtextBox
Button 1 - 5 = Used to select font style
Buttons 6 - 14 = Used to select colours
Button 15 = Choose font
OK once you have done that and arranged the controls as you want them you need to stretch out the richtextbox so it fits most of the form, make it nice and big.
Then you can simply copy and paste this code over:
If everything went ok you should now be able to run and use your basic text editor
.
Source-Code: Happy coding cooll;
I was just going through my project folder and found this document editor I was working on some time ago. Its only basic but may help you if you want to make a text editor.

Features include:
Save & Load as *.rtf file (saves font/sizes/colour etc rather than just plain text)
Change text colour
Change text font/size
Change font style
Here is how to make this little application. First you will need to add the following controls to your form:
MenuStrip - add 3 fields into this control "Save"..."Load"...and "Exit"
14 Buttons
1 RichtextBox
Button 1 - 5 = Used to select font style
Buttons 6 - 14 = Used to select colours
Button 15 = Choose font
OK once you have done that and arranged the controls as you want them you need to stretch out the richtextbox so it fits most of the form, make it nice and big.
Then you can simply copy and paste this code over:
Code: Select all
Public Class Form1
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
RichTextBox1.SelectionColor = Color.LightSlateGray
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RichTextBox1.SelectionFont = New Font(Me.RichTextBox1.SelectionFont, FontStyle.Bold)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
RichTextBox1.SelectionFont = New Font(Me.RichTextBox1.SelectionFont, FontStyle.Regular)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
RichTextBox1.SelectionFont = New Font(Me.RichTextBox1.SelectionFont, FontStyle.Italic)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
RichTextBox1.SelectionFont = New Font(Me.RichTextBox1.SelectionFont, FontStyle.Strikeout)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
RichTextBox1.SelectionFont = New Font(Me.RichTextBox1.SelectionFont, FontStyle.Underline)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
RichTextBox1.SelectionColor = Color.Red
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
RichTextBox1.SelectionColor = Color.Blue
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
RichTextBox1.SelectionColor = Color.Purple
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
RichTextBox1.SelectionColor = Color.Black
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
RichTextBox1.SelectionColor = Color.Pink
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
RichTextBox1.SelectionColor = Color.Yellow
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
RichTextBox1.SelectionColor = Color.Green
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
RichTextBox1.SelectionColor = Color.Orange
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim savefiledialog1 As New SaveFileDialog
savefiledialog1.Title = "Save File"
savefiledialog1.FileName = "*.rtf"
savefiledialog1.Filter = "RTF |*.rtf"
If savefiledialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
RichTextBox1.SaveFile(savefiledialog1.FileName, RichTextBoxStreamType.RichText)
End If
End Sub
Private Sub LoadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadToolStripMenuItem.Click
Dim openfiledialog1 As New OpenFileDialog
openfiledialog1.Title = "Save File"
openfiledialog1.FileName = "*.rtf"
openfiledialog1.Filter = "RTF |*.rtf"
If openfiledialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
RichTextBox1.LoadFile(openfiledialog1.FileName, RichTextBoxStreamType.RichText)
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
Dim fontdialog1 As New FontDialog
If fontdialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
RichTextBox1.SelectionFont = fontdialog1.Font
End If
End Sub
End Class
If everything went ok you should now be able to run and use your basic text editor

Source-Code: Happy coding cooll;