07-03-2011, 03:19 PM
Hey everybody i just thought that i would make a tutorial on how to make an advanced text editor in Visual BasicBiggrin.
ATTENTION
Basic knowledge of the VB GUI is recommend.
Ok so first off open up VB and click on new windows forms application and name it (whatever you want to name you text editor).
Ok so know that we have that done re size the form to the size that you want it to be and disable the Show Icon feature or use one of your own.
know name the name of the form to (the name of you editor).
Know go the the toolbox menu and add a tool strip menu.
In the tool strip menu make the first box called File and then add some more sub menus as follows.
New
Open
Save
Save as..
Print
Text To Speech
that's all that will be included in the File menu.
Now add another menu to the left of it called Edit and in edit add this
Undo
Redo
Cut
Copy Paste
Select all
That's all for this menu
Next menu will be called Format in Format add these sub menus
Font in font make another menu going out the side called Type and also include color.
and Background under neath Font
That's all for Format
Those are the Menus in the menu strip.
Know in the form add a Text box and fill the rest of the free space and know you have the GUI of your text editor know for the coding yeahRoflmao
OK know the code for New in the menu will be as follows:
OK the code for Open in the menu strip will be as follows:
The code for save will be:
The code for save as... will be:
The code for print will be:
The code for Text To Speech will be:
The code for Undo is:
The code for Redo is:
Code for Copy:
Code Paste:
Code Select All:
The code for Type is:
The code for color is:
The code for Back Ground is:
That's all the code if u see that I may have missed something than by all means please let me know thank you.
ATTENTION
Basic knowledge of the VB GUI is recommend.
Ok so first off open up VB and click on new windows forms application and name it (whatever you want to name you text editor).
Ok so know that we have that done re size the form to the size that you want it to be and disable the Show Icon feature or use one of your own.
know name the name of the form to (the name of you editor).
Know go the the toolbox menu and add a tool strip menu.
In the tool strip menu make the first box called File and then add some more sub menus as follows.
New
Open
Save
Save as..
Text To Speech
that's all that will be included in the File menu.
Now add another menu to the left of it called Edit and in edit add this
Undo
Redo
Cut
Copy Paste
Select all
That's all for this menu
Next menu will be called Format in Format add these sub menus
Font in font make another menu going out the side called Type and also include color.
and Background under neath Font
That's all for Format
Those are the Menus in the menu strip.
Know in the form add a Text box and fill the rest of the free space and know you have the GUI of your text editor know for the coding yeahRoflmao
OK know the code for New in the menu will be as follows:
Code:
TextBox1.Text() = ""
OK the code for Open in the menu strip will be as follows:
Code:
Dim alltext As String = "", lineoftext As String
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName <> "" Then
Try
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
Do Until EOF(1)
lineoftext = LineInput(1)
alltext = alltext & lineoftext & vbCrLf
Loop
TextBox1.Text = alltext
Catch
Finally
FileClose(1)
End Try
End If
The code for save will be:
Code:
Dim save As New System.IO.StreamWriter("E:\settings\PW.urs")
save.Write(TextBox1.Text + ControlChars.NewLine)
save.Close()
Code:
SaveFileDialog1.Filter = "txt (*.txt) |*.txt"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(1, TextBox1.Text)
FileClose(1)
End If
Code:
Dim AB As New PrintDialog
Try
AB.ShowDialog()
TextBox1.Text = AB.PrintToFile
Catch ex As Exception
'Again, do nothing on exception
End Try
The code for Text To Speech will be:
Code:
Dim SAPI
SAPI = CreateObject("sapi.spvoice")
SAPI.Speak(textbox1.text)
Code:
TextBox1.Undo()
Code:
TextBox1.Redo()
Code:
Richtextbox1.copy()
Code:
TexBox1.Paste()
Code:
TextBox1.Selectall()
Code:
Dim FS As New FontDialog
Try
FS.ShowDialog()
TextBox1.Font = FS.Font
Catch ex As Exception
'Do nothing on exeption
End Try
Code:
Dim FC As New ColorDialog
Try
FC.ShowDialog()
TextBox1.ForeColor = FC.Color
Catch ex As Exception
'Again, do nothing on exception
End Try
Code:
Try
Dim dlg As ColorDialog = New ColorDialog
dlg.Color = TextBox1.BackColor()
If dlg.ShowDialog = System.Windows.Forms.DialogResult.OK Then
TextBox1.BackColor = dlg.Color
End If
Catch ex As Exception : End Try
End Sub
End Class