Writing A Text EditorThis is a featured page

This tutorial shows how to make a simple text editor.


First, make a new windows forms project and add a text box and three buttons to the form. at the top right of the textbox, there is a little arrow, click it and click multi-line, then resize it to almost the size of the form using the little dots at the corners, but leave some extra space at the bottom for the buttons.

place the buttons below the textbox and then go under properties and go to text and replace the first one with Save the second with Load and the last with New.

Then add the following code for the buttons:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveFileDialog1.ShowDialog()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OpenFileDialog1.ShowDialog()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Clear()
End Sub


And then add a savefile dialog and a openfile dialog and add this code for them:

Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text, True)
End Sub

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End Sub
End Class



Run the application and it should allow you to save the text you type into the textbox, load text and clear the textbox.


Mrgameruler
Mrgameruler
Latest page update: made by Mrgameruler , May 4 2008, 12:55 PM EDT (about this update About This Update Mrgameruler Edited by Mrgameruler


view changes

- complete history)
Keyword tags: programming vb
More Info: links to this page
There are no threads for this page.  Be the first to start a new thread.

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)