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 now on the Menustrip we want:
Now Under File we want:
Under Edit we want:
(Then right click insert separator)
(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:
(In the right order please)
It should now look like this.
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.
Now we need some buttons in TabControl2 Under the Home Tab
Add 4 Buttons
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
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.
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.
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:
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 Form1add at the bottom
Dim I As Integer = 1Now under
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End SubWe 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 + 1Now 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 + 1If 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 - 1Now 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 TryNow 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 IfNow back to Menustrip1 Click on Edit
Double Click undo
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
If TabControl1.TabCount = 0 Then End If Dim FS As New FontDialog FS.ShowDialog() CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Font = FS.FontNow go back to Format and Double click Colour
If TabControl1.TabCount = 0 Then End If Dim FC As New ColorDialog FC.ShowDialog() CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).ForeColor = FC.ColorNow last but Not least the about Box we made we need to call that:
Go to Menustrip one and double click about
AboutWordPad.ShowDialog() ‘This basically shows the dialogNow 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
( YouTube - Advanced Notepad in Visual Basic 2010 / 2008.) <<
Edited by CriticalError, 27 July 2010 - 03:57 AM.