Jump to content

How to make a advanced tabbed notepad in Visual Basic 2010/ 2008

- - - - -

  • Please log in to reply
7 replies to this topic

#1
CriticalError

CriticalError

    Newbie

  • Members
  • PipPipPip
  • 42 posts
Hello Programmers! In this tutorial I am going to show you how to make an advanced tabbed notepad in visual basic 2010 / 2008. (PDF and actual programme is at the bottom!
Let’s get started.

I will split this tutorial in to two (2) parts

PART A the design and behaviour of our application

And PART B the coding.

Let’s get started.
PART A –Design & Behaviour

Open VB and go to File>New Project>Windows Form Application> Call it whatever you like.

OK Click Form 1 and resize it to around 683,448. Then in the properties panel of Form 1 were it says minimum size change that to 683,448. Now in the properties panel go to MaximizeBox Change this to False. Then change the text of Form 1 to whatever you like.
OK done.
Now insert:

1 Menustrip
1 Tabcontrol.
1 SavefileDialog


OK now on the Menustrip we want:

File
Edit
Format
About

Now Under File we want:

Add Tab
Remove Tab
Open
Save
Exit


Under Edit we want:

Undo
Redo
(Then right click insert separator)
Cut
Copy
Paste
Delete
Clear All
Select All


Under Format:

Font
Colour


(We don’t need anything under About)

Now moving on to the Tabcontrol (TC) make the TC 667, 52 (width x Height) in the properties menu. OK now where it says Name Change it to Tabcontrol2. Then where it says Anchor change this to left, top, right. Now in the TC properties menu where it says collection click it and add another tab. Now we name each tab:

Home
Edit
Format


(In the right order please)
It should now look like this.

Attached File  Image2..JPG   25.34K   747 downloads

OK Now let’s go back to the Menustrip:
Click File>Add Tab>
Now when you click Add tab go to its properties. In the properties at the bottom it says ShortcutKey change it to Ctrl+Shift +A. Now you can do the same for the rest but make sure that you give them different shortcut keys. Here is mine.

Attached File  image3..JPG   18.8K   584 downloads
Now we need some buttons in TabControl2 Under the Home Tab
Add 4 Buttons
Name them:

Add Tab
Remove Tab
Open
Save


OK Once you have added the buttons you might want to make sure that they are all same size this is what we do at the top of Visual Basic there is a bar called Layout

Attached File  layoutbar..JPG   17.04K   344 downloads
This one if you don’t have it go to View>Toolars>layout
Now click all Four Buttons. (Ctrl and click each one)
Then on the toolbar bar click:
Remove horizontal spacing.

Align:
Middles
Top
Bottoms


Then

Make same size
Make same width
Make same Height

You can’t see the text but hover over each one and a tooltip will show.



Now you can add more buttons for the rest of the tabs (Edit, Format) your adding the same data from the menustrip once you done it should look like this.

Attached File  image5..JPG   26.94K   544 downloads

OK Last but not least add another tabcontrol then click the white triangle in the top right corner of the TC and click Remove Tab (both of them). Then in the properties click Anchor and set to Top, Left,right,Bottom.
Then resize the Tabcontrol to fit the document. Should now look like this:

Attached File  image 6..JPG   32.3K   734 downloads
Now last this is go to top of VB Go to Project>Add New Item>About Box
Edit the information in the about box it is pretty straight forward.

PART B - CODING

Now Double click Form1
At the top where it says
 Public Class Form1 
add at the bottom
 Dim I As Integer = 1 
Now under
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub

We want to add

  Dim Edit As New RichTextBox

        TabControl1.TabPages.Add(1, "Page " & I)

        TabControl1.SelectTab(I - 1)

        Edit.Name = "TE"

        Edit.Dock = DockStyle.Fill

        TabControl1.SelectedTab.Controls.Add(Edit)

        I = I + 1

 
Now this is going to add a page for us in the TabControl1
Now go back the design view and click the menustrip1 and under File double click Add Tab
And this code
 Dim Edit As New RichTextBox

        TabControl1.TabPages.Add(1, "Page " & I)

        TabControl1.SelectTab(I - 1)

        Edit.Name = "TE"

        Edit.Dock = DockStyle.Fill

        TabControl1.SelectedTab.Controls.Add(Edit)

        I = I + 1

 
If you noticed this is the same code as the first one hehe:P:P
Now go back and double click Remove Tab
Add this code
    If TabControl1.TabCount = 1 Then

            MsgBox("Error You Can't Remove The Last Page", MsgBoxStyle.Critical)

‘Now you can change the message to whatever you like

‘This code will not allow us to remove the last tabpage which automatically loads

‘If it did an error would occur.


            Exit Sub

        Else


        End If


        TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)

‘This bottom code is telling it to remove the selected tab and countdown minus (-) 1 (one)

        TabControl1.SelectTab(TabControl1.TabPages.Count - 1)

        I = I - 1

 
Now go back to Menustrip1 and Double click Open add this
 Dim OpenFileDialog1 As New OpenFileDialog

        Dim AllText As String = "", LineOfText As String = ""

‘This bottom code is telling it to search each and ever file type

        OpenFileDialog1.Filter = "All Files|*.*"

‘This bottom code basically shows the opendialog box

        OpenFileDialog1.ShowDialog()

        Try

            FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)

            Do Until EOF(1)

                LineOfText = LineInput(1)

                AllText = AllText & LineOfText & vbCrLf

            Loop

            CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text = AllText

        Catch


        Finally

            FileClose(1)

        End Try

 
Now go back and double click save add this code
  Dim SaveFileDialog1 As New SaveFileDialog

‘The bottom code is shows which file types we can save it as you can add

‘More file types by using the same method

‘You can add html and other types if you like

        SaveFileDialog1.Filter = "Rich Text Files|*.rtf|Text Files|*.txt"

‘This tells it to show the dialog basically remember when you got

‘Something called “show Dialog” You can’t go back to the main programme without ‘closing

‘The first dialog showing

        SaveFileDialog1.ShowDialog()

        FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)

        PrintLine(1, CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text)

        FileClose(1)

 
OK now go back to menustrip1 and double click Exit add this:
  Dim msg As String

        Dim title As String

        Dim style As MsgBoxStyle

        Dim response As MsgBoxResult

        msg = "Are you sure?"   ' shows your message you can change it

        style = MsgBoxStyle.Information Or _

            MsgBoxStyle.YesNo ‘The dialog will be a Yes No answer

        title = "Youtite"   ' What did you name you application?

        response = MsgBox(msg, style, title)

        If response = MsgBoxResult.Yes Then   ' if the user chooses Yes it is going to execute the Me.Close() which will close the programme

‘Else it will still show up.

            

            Me.Close()

        Else

            

            Me.Show()

        End If

 
Now back to Menustrip1 Click on Edit
Double Click undo
Enter this:
 CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Undo()

Ok now the code for this is simple for the rest of the items on Menustri p1 Edit

Just copy that and at the after the (dot) . Put like Redo() Select All () etc..
For Delete the code is same as cut here:
 CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).cut()

 
No clear All is different
Go to Menu strip1 and Edit>Clear all
Enter this code:
 

‘This will emplty the selected Tab text

CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text = “”

 
Now move on to Format
Double Click Font
Enter this
 If TabControl1.TabCount = 0 Then


        End If


        Dim FS As New FontDialog

        FS.ShowDialog()

        CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Font = FS.Font

 
Now go back to Format and Double click Colour
Enter this:
 If TabControl1.TabCount = 0 Then



        End If

        Dim FC As New ColorDialog

        FC.ShowDialog()

        CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).ForeColor = FC.Color

 

Now last but Not least the about Box we made we need to call that:
Go to Menustrip one and double click about
Add:
 AboutWordPad.ShowDialog()

‘This basically shows the dialog

Now for those buttons Just copy and paste the same code that we have just inserted for the right buttons and then you’re done!

If you need any help just ask here or PM me I will be happy to help.

(Sorry for any bad bad mistakes)

You can see the one I made and the PDF of this document

[ATTACH]3153[/ATTACH]

[ATTACH]3154[/ATTACH]

( YouTube - Advanced Notepad in Visual Basic 2010 / 2008.) <<

Edited by CriticalError, 27 July 2010 - 03:57 AM.


#2
Demon

Demon

    Newbie

  • Members
  • PipPip
  • 18 posts
Very,very nice if I were gay I'd kiss you :thumbup:

#3
Dcurvez

Dcurvez

    Newbie

  • Members
  • Pip
  • 1 posts
great tutorial !
very nicely explained and easy to understand!
thank you :)

#4
VisualCode

VisualCode

    Newbie

  • Members
  • PipPip
  • 13 posts
Thank you ! :D This helped me a lot.

#5
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Thanks!!!
Good tutorial and helped me alot ^^!
I got one question:
~Could you help me with this: When you press 'Add Tab' there will be new tab with name 'Page (number)' but now I want to create this:
When you press the Add Tab button there will pop-up text box and you can create your own name to tab , get it? ;)

anyways thanks

Young student from Finland!
PS: 15-year-old! :)


#6
CriticalError

CriticalError

    Newbie

  • Members
  • PipPipPip
  • 42 posts
Its possible, you would have to create a new forum, with a textbox and a button then.

When someone adds a new tab show the popup menu.

on the button event, the code would be something like this:

tabcontrol1.tabname = popmenu.textbox1.text

I don't know exact code sorry but this should give you the idea on how it is done....

Hope it helps..

#7
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Thanks anyways, I'm trying to get it work and doing it right, GOOGLE is good weapon 2 ;)!

Young student from Finland!
PS: 15-year-old! :)


#8
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Now I created another form and when you press 'Add Tab' the form will open, and there is textbox which name is tabName and button OK which closes the form (Me.Close()) and how I can now do that the tabName will be tabs name? :s

Young student from Finland!
PS: 15-year-old! :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users