Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text Editor in VB for beginners
#1
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.
Reply
#2
Pictures always help beginners Smile
My profession, you can call me a pothead, 'nuff said
Reply
#3
Remember to include hotkeys, you havn't added that. E.g. ctrl-v for paste ctrl-c for copy etc
Reply
#4
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
Reply
#5
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..
[Image: iddyEs.png]
Reply
#6
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.
Reply
#7
This looks good I am sure beginners could use this.
Reply
#8
Nice tut could help out a lot of people.
Reply
#9
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.
Reply
#10
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Source Codes For Beginners Pt.1 SouR'D 14 3,743 11-25-2012, 10:36 PM
Last Post: ƃu∀ ıʞƃu∀
  Source Codes For Beginners Pt.2 SouR'D 9 3,113 11-25-2012, 10:35 PM
Last Post: ƃu∀ ıʞƃu∀
  [RELEASE]SF-TutPad "Tutorial Editor" [RELEASE] Digital-Punk 28 8,691 08-11-2012, 11:25 PM
Last Post: Kenneth
  TextBox2.Text | Transfer Text to ListBox Die 3 2,379 01-02-2012, 06:09 PM
Last Post: AceInfinity
  [RELEASE] Right Click Menu Editor Win 7 [RELEASE] FizzyMentos 4 1,104 12-11-2011, 04:05 PM
Last Post: HF~Legend

Forum Jump:


Users browsing this thread: 3 Guest(s)