Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub MsubExit_Click(sender As Object, e As EventArgs) Handles MsubExit.Click
- If MessageBox.Show("Are you want to exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
- 'you can use the more method
- '1- End
- '2- Close
- '3- Dispose
- '4- Application.Exit
- 'but please remeber the above method is difference but is a normally we can use close method
- Me.Close()
- 'Me.Dispose()
- 'End
- 'Application.Exit()
- End If
- End Sub
- Private Sub MSubNew_Click(sender As Object, e As EventArgs) Handles MSubNew.Click
- 'check if there text added to textbox
- If txtData.Modified Then
- 'if text in Textbox is been changed , the My Notepad App Ask
- Dim a As MsgBoxResult
- a = MsgBox("Do you want to save change to " & Me.Text, MsgBoxStyle.YesNoCancel, "New Document")
- If a = MsgBoxResult.No Then
- 'you can set clear textbox by default method or you can set string space the default method set null value but is not better. like this you can set string space is better
- 'txtData.Clear()
- txtData.Text = ""
- ElseIf a = MsgBoxResult.Cancel Then
- ElseIf a = MsgBoxResult.Yes Then
- SfdNotepad.ShowDialog()
- 'write text to Text File...
- My.Computer.FileSystem.WriteAllText(SfdNotepad.FileName, txtData.Text, False)
- txtData.Text = ""
- TsLbNotepad.Text = "Ready Saved ...."
- Else
- txtData.Text = ""
- End If
- End If
- End Sub
- Private Sub txtData_TextChanged(sender As Object, e As EventArgs) Handles txtData.TextChanged
- TsLbNotepad.Text = ""
- End Sub
- Private Sub MSubFont_Click(sender As Object, e As EventArgs) Handles MSubFont.Click
- 'get default font of FontLDialog
- FdNotepad.ShowDialog()
- txtData.Font = FdNotepad.Font
- End Sub
- Private Sub MsubOpen_Click(sender As Object, e As EventArgs) Handles MsubOpen.Click
- 'check if text is added
- If txtData.Modified Then
- 'if text of Textbox is changed, so ask
- Dim a As MsgBoxResult
- a = MsgBox("Do you want to save change to" & OfdNotepad.FileName, MsgBoxStyle.YesNoCancel, "Open Document")
- If a = MsgBoxResult.No Then
- OfdNotepad.ShowDialog()
- txtData.Text = My.Computer.FileSystem.ReadAllText(OfdNotepad.FileName)
- Me.Text = OfdNotepad.FileName
- ElseIf a = MsgBoxResult.Cancel Then
- 'nothing
- ElseIf a = MsgBoxResult.Yes Then
- SfdNotepad.ShowDialog()
- My.Computer.FileSystem.WriteAllText(SfdNotepad.FileName, txtData.Text, False)
- txtData.Text = ""
- End If
- Else
- 'if textbox still the same
- OfdNotepad.ShowDialog()
- Try
- txtData.Text = My.Computer.FileSystem.ReadAllText(OfdNotepad.FileName)
- Me.Text = OfdNotepad.FileName
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End If
- End Sub
- Private Sub MsubSave_Click(sender As Object, e As EventArgs) Handles MsubSave.Click
- If SfdNotepad.ShowDialog = Windows.Forms.DialogResult.OK Then
- 'check exist file
- If My.Computer.FileSystem.FileExists(SfdNotepad.FileName) Then
- If MessageBox.Show(SfdNotepad.FileName & " Already exist file do you want to replace its?", "File Exist", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
- SfdNotepad.ShowDialog()
- Else
- My.Computer.FileSystem.WriteAllText(SfdNotepad.FileName, txtData.Text, False)
- End If
- End If
- Else
- 'use try catch
- Try
- My.Computer.FileSystem.WriteAllText(SfdNotepad.FileName, txtData.Text, False)
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End If
- End Sub
- Private Sub MsubSaveAs_Click(sender As Object, e As EventArgs) Handles MsubSaveAs.Click
- If SfdNotepad.ShowDialog = Windows.Forms.DialogResult.OK Then
- My.Computer.FileSystem.WriteAllText(SfdNotepad.FileName, txtData.Text, False)
- txtData.Text = ""
- TsLbNotepad.Text = "Saved file ..."
- End If
- End Sub
- Private Sub MsubPageSetup_Click(sender As Object, e As EventArgs) Handles MsubPageSetup.Click
- 'initialize page setting
- PsdNotepad.PageSettings = New Printing.PageSettings
- 'hide the network button if you want
- PsdNotepad.ShowNetwork = False
- If PsdNotepad.ShowDialog = Windows.Forms.DialogResult.OK Then
- Dim s() As Object = New Object() {PsdNotepad.PageSettings.Margins, PsdNotepad.PageSettings.PaperSize, PsdNotepad.PageSettings.Landscape, PsdNotepad.PrinterSettings.PrinterName, PsdNotepad.PrinterSettings.PrintRange}
- End If
- End Sub
- Private Sub MsubPrintPreview_Click(sender As Object, e As EventArgs) Handles MsubPrintPreview.Click
- PpdNotepad.Document = PDoc
- PpdNotepad.ShowDialog()
- End Sub
- Private Sub PDoc_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PDoc.PrintPage
- Static c_char, c_line As Integer
- Dim tfont As Font = txtData.Font
- Dim h, w, left, top As Integer
- With PDoc.DefaultPageSettings
- h = .PaperSize.Height - .Margins.Top - .Margins.Bottom
- w = .PaperSize.Width - .Margins.Left - .Margins.Right
- left = PDoc.DefaultPageSettings.Margins.Left
- top = PDoc.DefaultPageSettings.Margins.Top
- End With
- e.Graphics.DrawRectangle(Pens.Black, New Rectangle(left, top, w, h))
- If PDoc.DefaultPageSettings.Landscape Then
- Dim i As Integer
- i = h
- h = w
- w = i
- End If
- Dim lines As Integer = CInt(Math.Round(h / txtData.Height))
- Dim j As New Rectangle(left, top, w, h)
- Dim frt As StringFormat
- If Not txtData.WordWrap Then
- frt = New StringFormat(StringFormatFlags.NoWrap)
- frt.Trimming = StringTrimming.EllipsisWord
- Dim k As Integer
- For k = c_line To Math.Min(c_line + lines, txtData.Lines.Length - 1)
- e.Graphics.DrawString(txtData.Lines(k), tfont, Brushes.Black, New Rectangle(left, top + tfont.Height * (k - c_line), w, tfont.Height), frt)
- Next
- c_line += lines
- If c_line >= txtData.Lines.Length Then
- e.HasMorePages = False
- c_line = 0
- Else
- e.HasMorePages = True
- End If
- Exit Sub
- End If
- frt = New StringFormat(StringFormatFlags.LineLimit)
- Dim l, c As Integer
- e.Graphics.MeasureString(Mid(txtData.Text, c_char + 1), tfont, New SizeF(w, h), frt, c, l)
- If c_char + c < txtData.Text.Length Then If txtData.Text.Substring(c_char + c, 1) <> " " And txtData.Text.Substring(c_char + c, 1) <> vbLf Then
- While c > 0
- txtData.Text.Substring(c_char + c, 1)
- c -= 1
- End While
- c += 1
- End If
- End If
- e.Graphics.DrawString(txtData.Text.Substring(c_char, c), tfont, Brushes.Black, j, frt)
- c_char = c_char + c
- If c_char < txtData.Text.Length Then e.HasMorePages = True Else e.HasMorePages = False c_char = 0 End If End Sub Private Sub MsubPrint_Click(sender As Object, e As EventArgs) Handles MsubPrint.Click With PdNotepad If .ShowDialog = Windows.Forms.DialogResult.OK Then PDoc.Print() End If End With End Sub Private Sub MSubUndo_Click(sender As Object, e As EventArgs) Handles MSubUndo.Click 'check user click undo If txtData.CanUndo Then txtData.Undo() End If End Sub Private Sub MSubCut_Click(sender As Object, e As EventArgs) Handles MSubCut.Click My.Computer.Clipboard.Clear() If txtData.SelectionLength > 0 Then
- My.Computer.Clipboard.SetText(txtData.SelectedText)
- End If
- txtData.SelectedText = ""
- End Sub
- Private Sub MSubCopy_Click(sender As Object, e As EventArgs) Handles MSubCopy.Click
- My.Computer.Clipboard.Clear()
- If txtData.SelectionLength > 0 Then
- My.Computer.Clipboard.SetText(txtData.SelectedText)
- End If
- End Sub
- Private Sub MSubPast_Click(sender As Object, e As EventArgs) Handles MSubPast.Click
- If My.Computer.Clipboard.ContainsText Then
- txtData.Paste()
- End If
- End Sub
- Private Sub MSubSelectall_Click(sender As Object, e As EventArgs) Handles MSubSelectall.Click
- txtData.SelectAll()
- End Sub
- Private Sub MSubFind_Click(sender As Object, e As EventArgs) Handles MSubFind.Click
- Dim j, k As String
- j = InputBox("Input Text here: ")
- k = InStr(txtData.Text, j)
- If k Then
- txtData.Focus()
- txtData.SelectionStart = k - 1
- txtData.SelectionLength = Len(j)
- Else
- MsgBox("text is not found.", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Not found")
- End If
- End Sub
- Private Sub MSubDelete_Click(sender As Object, e As EventArgs) Handles MSubDelete.Click
- txtData.SelectedText = ""
- End Sub
- Private Sub MSubReplace_Click(sender As Object, e As EventArgs) Handles MSubReplace.Click
- With Findata
- .txtReplace.Focus()
- If .ShowDialog = Windows.Forms.DialogResult.OK Then
- 'check text on Textbox and make replace it
- If txtData.Text.Contains(.txtReplace.Text) Then
- txtData.Text = txtData.Text.Replace(.txtReplace.Text, .txtTo.Text)
- End If
- End If
- End With
- End Sub
- Private Sub MSubDateTime_Click(sender As Object, e As EventArgs) Handles MSubDateTime.Click
- 'check textbox focus or not
- If txtData.Focus = True Then
- txtData.Text += Now
- End If
- End Sub
- Private Sub MSubStatusBar_Click(sender As Object, e As EventArgs) Handles MSubStatusBar.Click
- If MSubStatusBar.CheckState = CheckState.Checked Then
- SsNotepad.Visible = False
- MSubStatusBar.CheckState = CheckState.Unchecked
- Else
- SsNotepad.Visible = True
- MSubStatusBar.CheckState = CheckState.Checked
- End If
- End Sub
- Private Sub MSubFindNext_Click(sender As Object, e As EventArgs) Handles MSubFindNext.Click
- MSubFind_Click(sender, e)
- End Sub
- Private Sub AboutNotepadToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutNotepadToolStripMenuItem.Click
- AboutBox1.ShowDialog()
- End Sub
- Private Sub MSubFontColor_Click(sender As Object, e As EventArgs) Handles MSubFontColor.Click
- CDNotepad.ShowDialog()
- txtData.ForeColor = CDNotepad.Color
- End Sub
- Private Sub MSubBackgroundColor_Click(sender As Object, e As EventArgs) Handles MSubBackgroundColor.Click
- CDNotepad.ShowDialog()
- txtData.BackColor = CDNotepad.Color
- End Sub
- Private Sub MSubLeft_Click(sender As Object, e As EventArgs) Handles MSubLeft.Click
- 'txtData.TextAlign()
- 'we can't use it if you want to use it you replaace textbox to richtextbox
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement