Author Topic: [Tutorials][Vb.net][C#][beginner]Make you Own Notepad  (Read 8155 times)

0 Members and 2 Guests are viewing this topic.

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
[Tutorials][Vb.net][C#][beginner]Make you Own Notepad
« on: December 07, 2010, 10:08:00 pm »
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 Project
and 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 Notepad

First, 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 False
then 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 Menustrip

Click 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:
  • Save
  • Open 
  • Exit


for the 4th item: Click right mouse on of menu, goto Insert --> Seperator
Drag and move it to the right Position.

now you're File menu is Finished,

now type in the Empty Space right next to File, Settings
and 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:
  • Color
  • Font

Now your Settings Menu is Finished

We are almost done, with the looks, but were going to add Shortcutkeys
just 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 Notepad

Before 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 [bSub/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:
Code: (vb) [Select]
        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
Code: (C#) [Select]
            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":
Code: (vb) [Select]
Imports System.Text
Imports System.IO
Code: (C#) [Select]
using System.Text;
using  System.IO;

this will make things easier for us
instead of doing something like this:
Code: [Select]
System.IO.File.WriteallTextit can be more like this:
Code: [Select]
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/void
and write in there this:
Code: (vb) [Select]
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
Code: (C#) [Select]
        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:
Code: (vb) [Select]
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
Code: (C#) [Select]
private void ColourToolStripMenuItem_Click()
        {
            if (ColorDialog1.ShowDialog == Windows.Forms.DialogResult.OK)
            {
                RtbMain.ForeColor = ColorDialog1.Color;
            }
        }

Font Code:
Code: (vb) [Select]
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
Code: (C#) [Select]
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:
Code: (vb) [Select]
Private sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End sub
Code: (C#) [Select]
private void ExitToolStripMenuItem_Click()
    {
    Application.Exit();
    }

Select All Code:
Code: (vb) [Select]
Private sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
        RtbMain.SelectAll()
    End sub
Code: (C#) [Select]
private void SelectAllToolStripMenuItem_Click()
{
    RtbMain.SelectAll();
    }

Copy Code:
Code: (vb) [Select]
Private sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
        RtbMain.Copy()
    End sub
Code: (C#) [Select]
private void CopyToolStripMenuItem_Click()
{
RtbMain.Copy();
}

Cut Code:
Code: [Select]
    Private sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
        RtbMain.Cut()
    End sub
Code: (C#) [Select]
private void CutToolStripMenuItem_Click()
{
RtbMain.Cut();
}

Paste Code:
Code: (vb) [Select]
Private sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
        RtbMain.Paste()
    End sub
Code: (C#) [Select]
private void PasteToolStripMenuItem_Click()
{
    RtbMain.Paste();
    }

Undo Code:
Code: (vb) [Select]
Private sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click
        RtbMain.Undo()
    End sub
Code: (C#) [Select]
private void UndoToolStripMenuItem_Click()
{
        RtbMain.Undo();
    }

Redo Code:
Code: (vb) [Select]
Private sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem.Click
        RtbMain.Redo()
    End sub
Code: (C#) [Select]
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


« Last Edit: July 01, 2011, 08:26:36 pm by Huntondoom »
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: [Tutorials][Vb.net][C#][beginner]Make you Own Notepad
« Reply #1 on: July 01, 2011, 08:27:45 pm »
I have translated everything to C# and added it
not sure if it will work though :S
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline Zesh

  • Royal Highness
  • ****
  • Posts: 699
  • Cookies: 42
    • View Profile
Re: [Tutorials][Vb.net][C#][beginner]Make you Own Notepad
« Reply #2 on: July 01, 2011, 08:31:20 pm »
I have translated everything to C# and added it
not sure if it will work though :S

So you translated it to C# but you don't know if it will work? lol :P

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: [Tutorials][Vb.net][C#][beginner]Make you Own Notepad
« Reply #3 on: July 01, 2011, 08:56:46 pm »
So you translated it to C# but you don't know if it will work? lol :P
I did not test it :P
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

iMorg

  • Guest
Re: [Tutorials][Vb.net][C#][beginner]Make you Own Notepad
« Reply #4 on: July 01, 2011, 10:54:55 pm »

Offline Huntondoom

  • Baron
  • ****
  • Posts: 856
  • Cookies: 17
  • Visual C# programmer
    • View Profile
Re: [Tutorials][Vb.net][C#][beginner]Make you Own Notepad
« Reply #5 on: July 01, 2011, 11:00:32 pm »
......
I did test the vb.net version
but its a simple assembly Ill check it later
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline hanorotu

  • Dj Rapture
  • VIP
  • Majesty
  • *
  • Posts: 1173
  • Cookies: 98
  • ( ͡° ʖ ͡°)
    • View Profile
    • Rapture
Re: [Tutorials][Vb.net][C#][beginner]Make you Own Notepad
« Reply #6 on: January 16, 2013, 03:35:41 pm »
There any way you can update this?


Life is hard, then you get buried.
If you want to use my work all of my music is licensed under GNU General Public License v3 (GPL-3) - http://bit.ly/TfUOBA