Notepad in VB.NET

Public Class Form1
Inherits System.Windows.Forms.Form
Dim s, cp As String
Dim a, b As Integer

#Region ” Windows Form Designer generated code “

Public Sub New()
MyBase.New()

‘This call is required by the Windows Form Designer.
InitializeComponent()

‘Add any initialization after the InitializeComponent() call

End Sub

‘Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

‘Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

‘NOTE: The following procedure is required by the Windows Form Designer
‘It can be modified using the Windows Form Designer.
‘Do not modify it using the code editor.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem10 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem12 As System.Windows.Forms.MenuItem
Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
Friend WithEvents MenuItem13 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem15 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem16 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem17 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem18 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem19 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItem16 = New System.Windows.Forms.MenuItem
Me.MenuItem17 = New System.Windows.Forms.MenuItem
Me.MenuItem18 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.MenuItem10 = New System.Windows.Forms.MenuItem
Me.MenuItem13 = New System.Windows.Forms.MenuItem
Me.MenuItem14 = New System.Windows.Forms.MenuItem
Me.MenuItem15 = New System.Windows.Forms.MenuItem
Me.MenuItem19 = New System.Windows.Forms.MenuItem
Me.MenuItem11 = New System.Windows.Forms.MenuItem
Me.MenuItem12 = New System.Windows.Forms.MenuItem
Me.FontDialog1 = New System.Windows.Forms.FontDialog
Me.SuspendLayout()

‘RichTextBox1

Me.RichTextBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.RichTextBox1.Location = New System.Drawing.Point(0, 0)
Me.RichTextBox1.Name = “RichTextBox1″
Me.RichTextBox1.ShowSelectionMargin = True
Me.RichTextBox1.Size = New System.Drawing.Size(292, 266)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = “”

‘OpenFileDialog1

Me.OpenFileDialog1.DefaultExt = “txt”

‘SaveFileDialog1

Me.SaveFileDialog1.DefaultExt = “txt”

‘MainMenu1

Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem7, Me.MenuItem13, Me.MenuItem11})

‘MenuItem1

Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5, Me.MenuItem16, Me.MenuItem6})
Me.MenuItem1.Text = “File”

‘MenuItem2

Me.MenuItem2.Index = 0
Me.MenuItem2.Shortcut = System.Windows.Forms.Shortcut.F1
Me.MenuItem2.Text = “New”

‘MenuItem3

Me.MenuItem3.Index = 1
Me.MenuItem3.Shortcut = System.Windows.Forms.Shortcut.F2
Me.MenuItem3.Text = “Open”

‘MenuItem4

Me.MenuItem4.Index = 2
Me.MenuItem4.Shortcut = System.Windows.Forms.Shortcut.F3
Me.MenuItem4.Text = “Save”

‘MenuItem5

Me.MenuItem5.Index = 3
Me.MenuItem5.Shortcut = System.Windows.Forms.Shortcut.F4
Me.MenuItem5.Text = “Save as”

‘MenuItem16

Me.MenuItem16.Index = 4
Me.MenuItem16.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem17, Me.MenuItem18})
Me.MenuItem16.Text = “print”

‘MenuItem17

Me.MenuItem17.Index = 0
Me.MenuItem17.Shortcut = System.Windows.Forms.Shortcut.F5
Me.MenuItem17.Text = “print preview”

‘MenuItem18

Me.MenuItem18.Index = 1
Me.MenuItem18.Shortcut = System.Windows.Forms.Shortcut.F6
Me.MenuItem18.Text = “print document”

‘MenuItem6

Me.MenuItem6.Index = 5
Me.MenuItem6.Shortcut = System.Windows.Forms.Shortcut.F12
Me.MenuItem6.Text = “Exit”

‘MenuItem7

Me.MenuItem7.Index = 1
Me.MenuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem8, Me.MenuItem9, Me.MenuItem10})
Me.MenuItem7.Text = “Edit”

‘MenuItem8

Me.MenuItem8.Index = 0
Me.MenuItem8.Shortcut = System.Windows.Forms.Shortcut.CtrlC
Me.MenuItem8.Text = “Copy”

‘MenuItem9

Me.MenuItem9.Index = 1
Me.MenuItem9.Shortcut = System.Windows.Forms.Shortcut.CtrlX
Me.MenuItem9.Text = “Cut”

‘MenuItem10

Me.MenuItem10.Index = 2
Me.MenuItem10.Shortcut = System.Windows.Forms.Shortcut.CtrlV
Me.MenuItem10.Text = “Paste”

‘MenuItem13

Me.MenuItem13.Index = 2
Me.MenuItem13.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem14, Me.MenuItem15, Me.MenuItem19})
Me.MenuItem13.Shortcut = System.Windows.Forms.Shortcut.Alt1
Me.MenuItem13.Text = “Tools”

‘MenuItem14

Me.MenuItem14.Index = 0
Me.MenuItem14.Shortcut = System.Windows.Forms.Shortcut.CtrlA
Me.MenuItem14.Text = “Font”

‘MenuItem15

Me.MenuItem15.Index = 1
Me.MenuItem15.Shortcut = System.Windows.Forms.Shortcut.CtrlB
Me.MenuItem15.Text = “color”

‘MenuItem19

Me.MenuItem19.Index = 2
Me.MenuItem19.Text = “Font color”

‘MenuItem11

Me.MenuItem11.Index = 3
Me.MenuItem11.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem12})
Me.MenuItem11.Text = “Help”

‘MenuItem12

Me.MenuItem12.Index = 0
Me.MenuItem12.Shortcut = System.Windows.Forms.Shortcut.CtrlH
Me.MenuItem12.Text = “About”

‘Form1

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.AutoScroll = True
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.RichTextBox1)
Me.Icon = CType(resources.GetObject(“$this.Icon”), System.Drawing.Icon)
Me.KeyPreview = True
Me.Menu = Me.MainMenu1
Me.Name = “Form1″
Me.Text = “Form1″
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
If Me.OpenFileDialog1.ShowDialog = DialogResult.OK Then
s = Me.OpenFileDialog1.FileName()
Me.RichTextBox1.LoadFile(s, RichTextBoxStreamType.PlainText)
b = 1
End If
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
If b = 1 Then
Me.RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)
End If
If b = 0 Then

If Me.SaveFileDialog1.ShowDialog = DialogResult.OK Then
s = Me.SaveFileDialog1.FileName
Me.RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)
End If
b = 1
End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
a = 0
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
If a = 0 Then
RichTextBox1.Text = “”
ElseIf a = 1 Then
Dim i As Integer
i = MessageBox.Show(“Do you want to save your changes”, “Save file”, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
If i = DialogResult.Yes Then
If b = 1 Then
s = Me.SaveFileDialog1.FileName
Me.RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)

End If
If b = 0 Then

If Me.SaveFileDialog1.ShowDialog = DialogResult.OK Then
s = Me.SaveFileDialog1.FileName
Me.RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)
End If
b = 1
End If
RichTextBox1.Text = “”
a = 0
b = 0

ElseIf i = DialogResult.No Then
RichTextBox1.Text = “”
a = 0
b = 0
End If

End If

End Sub

Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
If Me.SaveFileDialog1.ShowDialog = DialogResult.OK Then
s = Me.SaveFileDialog1.FileName
Me.RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)
End If

End Sub

Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
If a = 0 Then
Me.Close()
ElseIf a = 1 Then
Dim i As Integer
i = MessageBox.Show(“Do you want to save your changes”, “Save file”, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)
If i = DialogResult.Yes Then
If b = 1 Then
s = Me.SaveFileDialog1.FileName
Me.RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)

End If
If b = 0 Then

If Me.SaveFileDialog1.ShowDialog = DialogResult.OK Then
s = Me.SaveFileDialog1.FileName
Me.RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)
End If
b = 1
End If
Me.Close()
a = 0
b = 0

ElseIf i = DialogResult.No Then

End If

End If

End Sub

Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged

End Sub

Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
a = 1

End Sub

Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
RichTextBox1.Copy()
‘cp = RichTextBox1.SelectedText
a = 1

End Sub

Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
RichTextBox1.Cut()
‘cp = RichTextBox1.SelectedText
‘RichTextBox1.SelectedText = “”
a = 1

End Sub

Private Sub MenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem10.Click
RichTextBox1.Paste()

End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.FontDialog1.ShowDialog = DialogResult.OK Then
Me.RichTextBox1.Font = Me.FontDialog1.Font
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub ToolBar1_ButtonClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
End Sub

Private Sub MenuItem14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem14.Click
If Me.FontDialog1.ShowDialog = DialogResult.OK Then
Me.RichTextBox1.Font = Me.FontDialog1.Font
End If

End Sub

Private Sub MenuItem15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem15.Click
If Me.ColorDialog1.ShowDialog = DialogResult.OK Then
Me.RichTextBox1.BackColor = Me.ColorDialog1.Color
End If
End Sub

Private Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem12.Click
MsgBox(“Made by SUSHANT KUMAR id:144″)
End Sub

Private Sub MenuItem18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem18.Click
Dim pr As String
pr = Me.PrintDialog1.PrintToFile

End Sub

Private Sub MenuItem17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem17.Click

End Sub

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

End Sub

Private Sub MenuItem19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem19.Click
If Me.ColorDialog1.ShowDialog = DialogResult.OK Then
End If
End Sub
End Class

15 thoughts on “Notepad in VB.NET

  1. pawan says:

    plz show with this code its application…

    so that the complete working of nottepad is easy to undrstand

    plz make it fast

  2. Ashish Kumar Singh says:

    How to create a notepad in VB.NET. please send me easy coading.
    and
    “Dim pr As String”
    what means of this lines. please send me answer.

  3. Andrea says:

    the code give me 3 errors (I use VB 2010) can you correct them?
    1- Protected Overrides Sub Dispose(disposing As Boolean…. line 7
    2- Private Sub InitializeComponent() …. line 24
    3- ‘components’ is already declared as ‘Private components AS System.ComponentsModel.IConteainer’ in this class line30

    Thanks you and sorry for my bad english

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s