Support Forums
Text Editor in VB for beginners - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: Text Editor in VB for beginners (/showthread.php?tid=20176)

Pages: 1 2


Text Editor in VB for beginners - Phoenix - 07-03-2011

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:
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()
The code for save as... will be:
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
The code for print will be:
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)
The code for Undo is:
Code:
TextBox1.Undo()
The code for Redo is:
Code:
TextBox1.Redo()
Code for Copy:
Code:
Richtextbox1.copy()
Code Paste:
Code:
TexBox1.Paste()
Code Select All:
Code:
TextBox1.Selectall()
The code for Type is:
Code:
Dim FS As New FontDialog
Try
FS.ShowDialog()
TextBox1.Font = FS.Font
Catch ex As Exception
'Do nothing on exeption
End Try
The code for color is:
Code:
Dim FC As New ColorDialog
Try
FC.ShowDialog()
TextBox1.ForeColor = FC.Color
Catch ex As Exception
'Again, do nothing on exception
End Try
The code for Back Ground is:
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
That's all the code if u see that I may have missed something than by all means please let me know thank you.


RE: Text Editor in VB for beginners - Firetech - 07-03-2011

Pictures always help beginners Smile


RE: Text Editor in VB for beginners - bckc - 07-04-2011

Remember to include hotkeys, you havn't added that. E.g. ctrl-v for paste ctrl-c for copy etc


RE: Text Editor in VB for beginners - AceInfinity - 07-04-2011

Here's my coded example of an advanced notepad that I created around a month ago. Still developing it.

They are all the same thing, just with different modifications, and names. A good list of the features is available through all the posts on the second link. I have encryption, find, tabs, and everything saves to a configuration file that can be loaded from later on "config.ini".
http://www.supportforums.net/showthread.php?tid=20191
http://www.supportforums.net/showthread.php?tid=18886


RE: Text Editor in VB for beginners - Coding Support - 07-23-2011

This can be very helpful for beginners, but i wanted to say to whoever is going to use this to learn, try to actually understand the code and not just Copy/Paste..


RE: Text Editor in VB for beginners - AceInfinity - 07-23-2011

If anyone requests a class to read from a configurable ini file, i'll release that later. Completely customized by myself for Setting names and Values, also with a comment or titlespace.


RE: Text Editor in VB for beginners - PURP - 07-24-2011

This looks good I am sure beginners could use this.


RE: Text Editor in VB for beginners - Kyle FYI™ - 07-26-2011

Nice tut could help out a lot of people.



RE: Text Editor in VB for beginners - Phoenix - 07-28-2011

Thanks for all the positive comments everybody appreciate although im not in VB development any more me and a group of people are working on a 3D game so im moving onto other languages like C# C++ and Java.


RE: Text Editor in VB for beginners - AceInfinity - 07-28-2011

(07-28-2011, 07:37 PM)RP Deliverance Wrote: Thanks for all the positive comments everybody appreciate although im not in VB development any more me and a group of people are working on a 3D game so im moving onto other languages like C# C++ and Java.

"VB" and "VB.net" are different. You can still do C#, and C++ in VB.