Make Your Own NotePad
For Beginners
by Huntondoom for Evilzone
This Tutorial is meant for people who just started with VB.net/C#
Visual Basic(vb.net) is colored blue
C# is colored red
Contents:0x00 What you need
0x01 Getting Started
0x02 The look of your Notepad
0x03 The Coding of your Notepad
0x00 What you need:- - A program like Microsoft Visual Studio
- - A little sense of Programming/logic
0x01 Getting Started First we start with a new project in Visual Studio, just simply go to
File --> New Projectand select from the menu:
Windows Forms Application(Found under: Visual Basic -> Windows)(Found under: C# -> Windows)and Click ok.
you'll see a standard
Windows Form, on this Form we'll be making our Notepad.
0x02 The look of your NotepadFirst, lets resize our form to a more suitable size, this size will be used as
default every time you start your notepad
now we're going to edit the
Form, click once on the form and goto the properties, look for
ShowIcon and set it to
Falsethen look for
Text, and enter there you name for your notepad
Open Up the
Toolbox, and look for the
Panel, then drag the
Panel onto your Form.
Click once on the form, and goto
Properties, and search for "
Dock", then set it to
Top now the panel has shifted to the Top of the Form, and it will always fill up the "Top" of your Form,
Drag another
Panel onto your Form, and set
Dock to
Fill,
this
Panel will now fill the rest of your Form.
In the Toolbox, look for the
Richtextbox, and drag and drop it into the Panel that which fills almost the whole form, now go to properties and
change the Name to:
RtbMain (in the properties)
and set Dock to Fill.
Now, go and look for
MenuStrip in the
Toolbox, then drag the
MenuStrip to the
Panel that fills the
Top, Resize the top
Panel so it fits nicely around the
MenustripClick on the first empty space in the
MenuStrip,
and type:
File and when you are done, click on the menu item you just made
Then a menu under
File opens up, there we are going to insert 4 new items.
just click and type these 3 things into one of the open spaces:
for the 4th item: Click right mouse on of menu, goto
Insert --> SeperatorDrag and move it to the right Position.
now you're
File menu is Finished,
now type in the Empty Space right next to
File, Settingsand now we are going to do the same as we did with the
File menu items
make sure these are all in the
Settings menu:- Text Settings
- Select All
- Copy
- Cut
- Paste
- Undo
- Redo
Then Click on
Text Settings and you'll see it opens up another side menu,
in there, type these 2:
Now your
Settings Menu is Finished
We are almost done, with the looks, but were going to add
Shortcutkeysjust goto
Properties and search for:
ShowShortcutkeys and set it to
True to each of all the Listed objects done below
Now we're going to add which keys, are going to corrospond with each off the listed objects, just goto
Properties and search for
ShortCutkeys, there you can Pick which keys you want to use.
here is the list of Objects that would need an shortcut.
- Save - Ctrl + S
- Open - Ctrl + O
- Select All - Ctrl + A
- Copy - Ctrl + C
- Cut - Ctrl + X
- Paste - Ctrl + V
- Undo - Ctrl + Z
- Redo - Ctrl + Shift + Z
now you're done with the looks,
next up: Coding
0x03 The Coding of your NotepadBefore we actually start with the coding, we'll need some extra things from the
Toolbox,
Open up the
Dialog Section, (or search for it).
and just drag and release anywhere on your form
these objects:
- ColorDialog
- FontDialog
- SaveFileDialog
- OpenFileDialog
these Dialogs will mostly help us with saving or opening a file,
and change settings as Font type, size and the color of the text.
Lets start with the
Save Sub/void,
double click on the
Save in your
File menu,
and you'll see it automatically creates a
Sub/void for the
Save Sub/void.
every [b
Sub/
void[/b] is triggered by an event, in this case, clicking on the save button
in your file menu, in that
Sub/
void write down the following:
SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
IO.File.WriteAllText(SaveFileDialog1.FileName, RtbMain.Text)
End If
SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
SaveFileDialog1.FilterIndex = 1;
SaveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (SaveFileDialog1.ShowDialog == Windows.Forms.DialogResult.OK)
{
IO.File.WriteAllText(SaveFileDialog1.FileName, RtbMain.Text);
}
Explanation of the code:This Code will set the usable Extension which will be used to save the file with,
and which Extension is the default one,
also in which folder you start browsing (of course this can be changed by the user)
the last section, the If statement, is to see if the
Ok button on the
SaveDialog was pressed and then it will save the Text (Rtbmain.text)
now you got to add these 2 things to the code,
and put it above
"Public Class Form1"/"namespace WindowsFormsApplication1":
Imports System.Text
Imports System.IO
using System.Text;
using System.IO;
this will make things easier for us
instead of doing something like this:
System.IO.File.WriteallText
it can be more like this:
File.WriteAllText
it will just make it so you wont have to type that much, or you get some extra function you probably had to recall through a long function,
now lets put in that
Open Sub/void, start the same as with the
Save Sub/voidand write in there this:
OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
RtbMain.Text = IO.File.ReadAllText(OpenFileDialog1.FileName).ToString
End If
OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
OpenFileDialog1.FilterIndex = 1;
OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (OpenFileDialog1.ShowDialog == Windows.Forms.DialogResult.OK)
{
RtbMain.Text = IO.File.ReadAllText(OpenFileDialog1.FileName).ToString();
}
Explanation of the Code:this is the function to read Text Files.
as you can see it looks very much the same, it is mostly the same as Save
but except for the RtbMain.text = IO......
this is because it says, Contents of the file goes into the richtextbox
the Color and Font Dialog are some what the same:
Color Code:Private Sub ColourToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColourToolStripMenuItem.Click
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
RtbMain.ForeColor = ColorDialog1.Color
End If
End Sub
private void ColourToolStripMenuItem_Click()
{
if (ColorDialog1.ShowDialog == Windows.Forms.DialogResult.OK)
{
RtbMain.ForeColor = ColorDialog1.Color;
}
}
Font Code:
Private sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
RtbMain.Font = FontDialog1.Font
End If
End sub
private void FontToolStripMenuItem_Click()
{
if (FontDialog1.ShowDialog == Windows.Forms.DialogResult.OK) {
RtbMain.Font = FontDialog1.Font;
}
}
as you can see they work pretty much the same as Open and Save, except you don't have to specify settings in the beginning
the dialog will give back the setting the user select and will be transfered to the Rtbmain which controls how every looks and does
now, we I'm just going to give you the more easy one for you to just to fill in:
Exit Code:Private sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End sub
private void ExitToolStripMenuItem_Click()
{
Application.Exit();
}
Select All Code:Private sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
RtbMain.SelectAll()
End sub
private void SelectAllToolStripMenuItem_Click()
{
RtbMain.SelectAll();
}
Copy Code:Private sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
RtbMain.Copy()
End sub
private void CopyToolStripMenuItem_Click()
{
RtbMain.Copy();
}
Cut Code: Private sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
RtbMain.Cut()
End sub
private void CutToolStripMenuItem_Click()
{
RtbMain.Cut();
}
Paste Code:Private sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
RtbMain.Paste()
End sub
private void PasteToolStripMenuItem_Click()
{
RtbMain.Paste();
}
Undo Code:Private sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click
RtbMain.Undo()
End sub
private void UndoToolStripMenuItem_Click()
{
RtbMain.Undo();
}
Redo Code:Private sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem.Click
RtbMain.Redo()
End sub
private void RedoToolStripMenuItem_Click()
{
RtbMain.Redo();
}
now you're done with everything, but you just have to build the thing
so goto
Build --> Build [project name]or just press F5
of course you can change things in your own notepad,
your result should look something like this:
I hope you'll keep continuing learning VB.net / C#, and that you'll have some great projects