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.
There are no threads for this page.
Be the first to start a new thread.