Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

countdown

  • Please log in to reply
18 replies to this topic

#1 CriticalError

CriticalError

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 185 posts

Posted 06 July 2010 - 04:15 AM

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.

Image2..JPG

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.

image3..JPG
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

layoutbar..JPG
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.

image5..JPG

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:

image 6..JPG
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.) <<

Attached Thumbnails

  • Image1..JPG
  • image4..JPG

Attached Files


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

  • 1

#2 Demon

Demon

    CC Newcomer

  • Just Joined
  • PipPip
  • 18 posts

Posted 19 September 2010 - 01:22 AM

Very,very nice if I were ** I'd kiss you :thumbup:
  • 0

#3 Dcurvez

Dcurvez

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 28 September 2010 - 05:27 PM

great tutorial !
very nicely explained and easy to understand!
thank you :)
  • 0

#4 VisualCode

VisualCode

    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 30 December 2010 - 04:55 PM

Thank you ! :D This helped me a lot.
  • 0

#5 Epatron

Epatron

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 54 posts

Posted 23 September 2011 - 11:24 AM

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
  • 0

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


#6 CriticalError

CriticalError

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 185 posts

Posted 23 September 2011 - 12:18 PM

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..
  • 0

#7 Epatron

Epatron

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 54 posts

Posted 23 September 2011 - 12:19 PM

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

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


#8 Epatron

Epatron

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 54 posts

Posted 24 September 2011 - 12:32 AM

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
  • 0

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


#9 tempatsampah

tempatsampah

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C, Java, C++, Objective-C, C#, PHP, (Visual) Basic, JavaScript, PL/SQL, Visual Basic .NET, Pascal, Ada, Logo, Assembly, ActionScript, VBScript, Others

Posted 08 July 2012 - 12:46 AM

thanks brother, :c-thumbup:
if you could explain how tab on top? please,please find me very dizzy :confused:
  • 0

#10 CriticalError

CriticalError

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 185 posts

Posted 08 July 2012 - 02:55 AM

thanks brother, :c-thumbup:
if you could explain how tab on top? please,please find me very dizzy :confused:


What do you mean by that?
  • 0

#11 CriticalError

CriticalError

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 185 posts

Posted 08 July 2012 - 05:19 AM

Agree thanks it help me a lot :thumbup1: good work

He means bro not brother.


Now I was referring to this line:

if you could explain how tab on top? please,please find me very dizzy
  • 0

#12 jonathanblu

jonathanblu

    CC Lurker

  • New Member
  • Pip
  • 4 posts
  • Programming Language:(Visual) Basic
  • Learning:(Visual) Basic

Posted 07 August 2012 - 12:56 PM

I have actually been getting around to making my own text editor like this. This will undoubtedly be a great help, but I do have one question. I intend to write it as a journal program, so what do you think the best way would be to password protect the program and my entries?
  • 0





Also tagged with one or more of these keywords: countdown