Simple Note Pad

Hi Future Office developers,

Take this is a simple sample notepad. Perhaps helpful for lots of you . Especially who just begin !


Imports System.io
Public Class FrmWpad
Inherits System.Windows.Forms.Form
#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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents StatusBarPanel1 As System.Windows.Forms.StatusBarPanel
Friend WithEvents StatusBarPanel2 As System.Windows.Forms.StatusBarPanel
Friend WithEvents StatusBarPanel3 As System.Windows.Forms.StatusBarPanel
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents WPad As System.Windows.Forms.RichTextBox
Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem18 As System.Windows.Forms.MenuItem
Friend WithEvents MnuFile As System.Windows.Forms.MenuItem
Friend WithEvents MnuNew As System.Windows.Forms.MenuItem
Friend WithEvents MnuOpen As System.Windows.Forms.MenuItem
Friend WithEvents MnuSave As System.Windows.Forms.MenuItem
Friend WithEvents MnuSaveAs As System.Windows.Forms.MenuItem
Friend WithEvents MnuPrint As System.Windows.Forms.MenuItem
Friend WithEvents MnuPreview As System.Windows.Forms.MenuItem
Friend WithEvents MnuExit As System.Windows.Forms.MenuItem
Friend WithEvents MnuEdit As System.Windows.Forms.MenuItem
Friend WithEvents MnuUndo As System.Windows.Forms.MenuItem
Friend WithEvents MnuRedo As System.Windows.Forms.MenuItem
Friend WithEvents MnuCut As System.Windows.Forms.MenuItem
Friend WithEvents MnuCopy As System.Windows.Forms.MenuItem
Friend WithEvents MnuPaste As System.Windows.Forms.MenuItem
Friend WithEvents MnuSelectAll As System.Windows.Forms.MenuItem
Friend WithEvents MnuTime As System.Windows.Forms.MenuItem
Friend WithEvents MnuFormat As System.Windows.Forms.MenuItem
Friend WithEvents MnuWordWrap As System.Windows.Forms.MenuItem
Friend WithEvents MnuFont As System.Windows.Forms.MenuItem
Friend WithEvents MnuView As System.Windows.Forms.MenuItem
Friend WithEvents MnuStatusBar As System.Windows.Forms.MenuItem
Friend WithEvents MnuHelp As System.Windows.Forms.MenuItem
Friend WithEvents MnuAbout As System.Windows.Forms.MenuItem
Friend WithEvents MnuBackColor As System.Windows.Forms.MenuItem
Friend WithEvents StbWPad As System.Windows.Forms.StatusBar
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MnuALeft As System.Windows.Forms.MenuItem
Friend WithEvents MnuARight As System.Windows.Forms.MenuItem
Friend WithEvents MnuCenter As System.Windows.Forms.MenuItem
Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FrmWpad))
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MnuFile = New System.Windows.Forms.MenuItem
Me.MnuNew = New System.Windows.Forms.MenuItem
Me.MnuOpen = New System.Windows.Forms.MenuItem
Me.MnuSave = New System.Windows.Forms.MenuItem
Me.MnuSaveAs = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MnuPrint = New System.Windows.Forms.MenuItem
Me.MnuPreview = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.MnuExit = New System.Windows.Forms.MenuItem
Me.MnuEdit = New System.Windows.Forms.MenuItem
Me.MnuUndo = New System.Windows.Forms.MenuItem
Me.MnuRedo = New System.Windows.Forms.MenuItem
Me.MenuItem14 = New System.Windows.Forms.MenuItem
Me.MnuCut = New System.Windows.Forms.MenuItem
Me.MnuCopy = New System.Windows.Forms.MenuItem
Me.MnuPaste = New System.Windows.Forms.MenuItem
Me.MenuItem18 = New System.Windows.Forms.MenuItem
Me.MnuSelectAll = New System.Windows.Forms.MenuItem
Me.MnuTime = New System.Windows.Forms.MenuItem
Me.MnuFormat = New System.Windows.Forms.MenuItem
Me.MnuWordWrap = New System.Windows.Forms.MenuItem
Me.MnuFont = New System.Windows.Forms.MenuItem
Me.MnuBackColor = New System.Windows.Forms.MenuItem
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MnuALeft = New System.Windows.Forms.MenuItem
Me.MnuARight = New System.Windows.Forms.MenuItem
Me.MnuCenter = New System.Windows.Forms.MenuItem
Me.MnuView = New System.Windows.Forms.MenuItem
Me.MnuStatusBar = New System.Windows.Forms.MenuItem
Me.MnuHelp = New System.Windows.Forms.MenuItem
Me.MnuAbout = New System.Windows.Forms.MenuItem
Me.StbWPad = New System.Windows.Forms.StatusBar
Me.StatusBarPanel1 = New System.Windows.Forms.StatusBarPanel
Me.StatusBarPanel2 = New System.Windows.Forms.StatusBarPanel
Me.StatusBarPanel3 = New System.Windows.Forms.StatusBarPanel
Me.WPad = New System.Windows.Forms.RichTextBox
Me.FontDialog1 = New System.Windows.Forms.FontDialog
Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuFile, Me.MnuEdit, Me.MnuFormat, Me.MnuView, Me.MnuHelp})
'
'MnuFile
'
Me.MnuFile.Index = 0
Me.MnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuNew, Me.MnuOpen, Me.MnuSave, Me.MnuSaveAs, Me.MenuItem6, Me.MnuPrint, Me.MnuPreview, Me.MenuItem9, Me.MnuExit})
Me.MnuFile.Text = "&File"
'
'MnuNew
'
Me.MnuNew.Index = 0
Me.MnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN
Me.MnuNew.Text = "&New"
'
'MnuOpen
'
Me.MnuOpen.Index = 1
Me.MnuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO
Me.MnuOpen.Text = "&Open..."
'
'MnuSave
'
Me.MnuSave.Index = 2
Me.MnuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS
Me.MnuSave.Text = "Save"
Me.MnuSave.Visible = False
'
'MnuSaveAs
'
Me.MnuSaveAs.Index = 3
Me.MnuSaveAs.Text = "Save As..."
'
'MenuItem6
'
Me.MenuItem6.Index = 4
Me.MenuItem6.Text = "-"
Me.MenuItem6.Visible = False
'
'MnuPrint
'
Me.MnuPrint.Index = 5
Me.MnuPrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP
Me.MnuPrint.Text = "Print..."
Me.MnuPrint.Visible = False
'
'MnuPreview
'
Me.MnuPreview.Index = 6
Me.MnuPreview.Text = "Print Preview"
Me.MnuPreview.Visible = False
'
'MenuItem9
'
Me.MenuItem9.Index = 7
Me.MenuItem9.Text = "-"
'
'MnuExit
'
Me.MnuExit.Index = 8
Me.MnuExit.Text = "Exit"
'
'MnuEdit
'
Me.MnuEdit.Index = 1
Me.MnuEdit.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuUndo, Me.MnuRedo, Me.MenuItem14, Me.MnuCut, Me.MnuCopy, Me.MnuPaste, Me.MenuItem18, Me.MnuSelectAll, Me.MnuTime})
Me.MnuEdit.Text = "&Edit"
'
'MnuUndo
'
Me.MnuUndo.Index = 0
Me.MnuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ
Me.MnuUndo.Text = "Undo"
'
'MnuRedo
'
Me.MnuRedo.Index = 1
Me.MnuRedo.Shortcut = System.Windows.Forms.Shortcut.CtrlY
Me.MnuRedo.Text = "Redo"
'
'MenuItem14
'
Me.MenuItem14.Index = 2
Me.MenuItem14.Text = "-"
'
'MnuCut
'
Me.MnuCut.Index = 3
Me.MnuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX
Me.MnuCut.Text = "Cut"
'
'MnuCopy
'
Me.MnuCopy.Index = 4
Me.MnuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC
Me.MnuCopy.Text = "Copy"
'
'MnuPaste
'
Me.MnuPaste.Enabled = False
Me.MnuPaste.Index = 5
Me.MnuPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV
Me.MnuPaste.Text = "Paste"
'
'MenuItem18
'
Me.MenuItem18.Index = 6
Me.MenuItem18.Text = "-"
'
'MnuSelectAll
'
Me.MnuSelectAll.Index = 7
Me.MnuSelectAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA
Me.MnuSelectAll.Text = "Select All"
'
'MnuTime
'
Me.MnuTime.Index = 8
Me.MnuTime.Shortcut = System.Windows.Forms.Shortcut.F5
Me.MnuTime.Text = "Time/Date"
'
'MnuFormat
'
Me.MnuFormat.Index = 2
Me.MnuFormat.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuWordWrap, Me.MnuFont, Me.MnuBackColor, Me.MenuItem1, Me.MnuALeft, Me.MnuARight, Me.MnuCenter})
Me.MnuFormat.Text = "F&ormat"
'
'MnuWordWrap
'
Me.MnuWordWrap.Checked = True
Me.MnuWordWrap.Index = 0
Me.MnuWordWrap.Text = "Word Wrap"
'
'MnuFont
'
Me.MnuFont.Index = 1
Me.MnuFont.Text = "Font..."
'
'MnuBackColor
'
Me.MnuBackColor.Index = 2
Me.MnuBackColor.Text = "Background Color..."
'
'MenuItem1
'
Me.MenuItem1.Index = 3
Me.MenuItem1.Text = "-"
'
'MnuALeft
'
Me.MnuALeft.Index = 4
Me.MnuALeft.Text = "Left Align"
'
'MnuARight
'
Me.MnuARight.Index = 5
Me.MnuARight.Text = "Right Align"
'
'MnuCenter
'
Me.MnuCenter.Index = 6
Me.MnuCenter.Text = "Center"
'
'MnuView
'
Me.MnuView.Index = 3
Me.MnuView.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuStatusBar})
Me.MnuView.Text = "&View"
'
'MnuStatusBar
'
Me.MnuStatusBar.Checked = True
Me.MnuStatusBar.Index = 0
Me.MnuStatusBar.Text = "Status Bar"
'
'MnuHelp
'
Me.MnuHelp.Index = 4
Me.MnuHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MnuAbout})
Me.MnuHelp.Text = "&Help"
'
'MnuAbout
'
Me.MnuAbout.Index = 0
Me.MnuAbout.Shortcut = System.Windows.Forms.Shortcut.F1
Me.MnuAbout.Text = "About SAM_WordPad"
'
'StbWPad
'
Me.StbWPad.Location = New System.Drawing.Point(0, 427)
Me.StbWPad.Name = "StbWPad"
Me.StbWPad.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel1, Me.StatusBarPanel2, Me.StatusBarPanel3})
Me.StbWPad.ShowPanels = True
Me.StbWPad.Size = New System.Drawing.Size(704, 22)
Me.StbWPad.TabIndex = 0
'
'StatusBarPanel1
'
Me.StatusBarPanel1.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
Me.StatusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None
Me.StatusBarPanel1.Text = "Press F1 for Help"
Me.StatusBarPanel1.Width = 600
'
'StatusBarPanel2
'
Me.StatusBarPanel2.Width = 50
'
'StatusBarPanel3
'
Me.StatusBarPanel3.Width = 38
'
'WPad
'
Me.WPad.AcceptsTab = True
Me.WPad.Dock = System.Windows.Forms.DockStyle.Fill
Me.WPad.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.WPad.HideSelection = False
Me.WPad.Location = New System.Drawing.Point(0, 0)
Me.WPad.Name = "WPad"
Me.WPad.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedBoth
Me.WPad.Size = New System.Drawing.Size(704, 427)
Me.WPad.TabIndex = 1
Me.WPad.Text = ""
'
'PrintPreviewDialog1
'
Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
Me.PrintPreviewDialog1.Enabled = True
Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
Me.PrintPreviewDialog1.Location = New System.Drawing.Point(125, 17)
Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
Me.PrintPreviewDialog1.Visible = False
'
'FrmWpad
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(704, 449)
Me.Controls.Add(Me.WPad)
Me.Controls.Add(Me.StbWPad)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Menu = Me.MainMenu1
Me.Name = "FrmWpad"
Me.Text = "Untitled - SAM_WordPad"
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuExit.Click
End
End Sub
Private Sub MnuStatusBar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuStatusBar.Click
StbWPad.Visible = Not StbWPad.Visible
MnuStatusBar.Checked = Not MnuStatusBar.Checked
End Sub
Private Sub MnuWordWrap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuWordWrap.Click
WPad.WordWrap = Not WPad.WordWrap
MnuWordWrap.Checked = Not MnuWordWrap.Checked
End Sub
Private Sub MnuTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuTime.Click
WPad.Text = WPad.Text & TimeString & " " & DateString
End Sub
Private Sub FrmWpad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub MnuSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuSelectAll.Click
WPad.SelectionStart = 0
WPad.SelectionLength = Len(WPad.Text)
End Sub
Private Sub MnuALeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuALeft.Click
WPad.SelectionAlignment = HorizontalAlignment.Left
End Sub
Private Sub MnuARight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuARight.Click
WPad.SelectionAlignment = HorizontalAlignment.Right
End Sub
Private Sub MnuCenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuCenter.Click
WPad.SelectionAlignment = HorizontalAlignment.Center
End Sub
Private Sub MnuCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuCut.Click
System.Windows.Forms.Clipboard.SetDataObject(WPad.SelectedText)
WPad.SelectedText = ""
MnuPaste.Enabled = True
End Sub
Private Sub MnuCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MnuCopy.Click
System.Windows.Forms.Clipboard.SetDataObject(WPad.SelectedText)
MnuPaste.Enabled = True
End Sub
Private Sub MnuPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MnuPaste.Click
WPad.Paste()
End Sub
Private Sub MnuUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuUndo.Click
WPad.Undo()
End Sub
Private Sub MnuRedo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuRedo.Click
WPad.Redo()
End Sub
Private Sub MnuFormat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuFormat.Click
End Sub
Private Sub MnuFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuFont.Click
FontDialog1.ShowColor = True
FontDialog1.ShowEffects = True
FontDialog1.ShowHelp = True
If FontDialog1.ShowDialog = DialogResult.OK Then
WPad.Font = FontDialog1.Font
WPad.ForeColor = FontDialog1.Color
End If
End Sub

Private Sub MnuBackColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuBackColor.Click
ColorDialog1.FullOpen = True
If ColorDialog1.ShowDialog = DialogResult.OK Then
WPad.BackColor = ColorDialog1.Color
End If
End Sub
Private Sub MnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuOpen.Click
Dim str As String
OpenFileDialog1.Filter = "Text Files (*.txt)*.txt All Files (*.*)*.*"
OpenFileDialog1.Multiselect = False
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
str = OpenFileDialog1.FileName
Dim ob As StreamReader = New StreamReader(str)
WPad.Text = ob.ReadToEnd()
ob.Close()
End If
End Sub
Private Sub MnuSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuSaveAs.Click
Dim str As String
SaveFileDialog1.Filter = "Text Files (*.txt)*.txt"
SaveFileDialog1.AddExtension = True
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
str = SaveFileDialog1.FileName
Dim ob As StreamWriter = New StreamWriter(str, False)
ob.Write(WPad.Text)
ob.Close()
End If
End Sub
End Class

Make a new *.vb class and post it all. Clear all the form before pasting.
Or create new (empty) one

0 comments:

Post a Comment