Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2015. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Text Editor
- '
- ' Author: Joseph L. Bolen
- ' Date Created: Feb 2015
- '
- ' Description: Simple plain text editor program with printing ability.
- '
- ' Documentation is at:
- ' App's screen image is at: http://imgur.com/TzWs9kO
- ' App's screen design time specs at: http://pastebin.com/bhinRQ5d
- ' App's Visual Basic .NET Event Procedures & TODO's is at
- ' http://pastebin.com/UZ4tcEpE
- ' App's Visual Basic .NET code is at http://pastebin.com/u/jaybeeoh
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '-------------------------------------------------------------------------------------------
- Imports System.IO
- Imports System.Security
- #Region " Declare class level variables"
- Public applicationTitle As String = My.Application.Info.Title
- Private Const fileFilter As String =
- "Plain Text (*.txt)|*.txt|" &
- "Log Files (*.log)|*.log|" &
- "All Files (*.*)|*.*"
- Private workingPathFile As String = String.Empty
- Private workingPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
- #End Region
- ' File Open option.
- Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) _
- Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
- If SaveChanges() Then
- SaveToolStripMenuItem_Click(sender, e)
- End If
- With OpenFileDialog1
- .Multiselect = False
- .Filter = fileFilter
- .DefaultExt = "txt"
- .FileName = String.Empty
- .InitialDirectory = workingPath
- If DialogResult.OK = .ShowDialog Then
- workingPathFile = .FileName
- GetFile()
- End If
- End With
- End Sub
- ' Read into the Textbox's text property the data from a file using My.Computer.FileSystem.
- Private Sub GetFile()
- Try
- With MyTextBox
- .Text = My.Computer.FileSystem.ReadAllText(workingPathFile, System.Text.Encoding.UTF8)
- .Modified = False
- .Select(0, 0)
- .Focus()
- End With
- workingPath = Path.GetDirectoryName(workingPathFile)
- Me.Text = applicationTitle & " - " & Path.GetFileName(workingPathFile)
- Catch ex As IOException
- MessageBox.Show(ex.Message, "File IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Catch ex As SecurityException
- MessageBox.Show(ex.Message, "File Permissions Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Catch ex As Exception
- MessageBox.Show("There was a problem opening the file selected." &
- ControlChars.NewLine & ex.Message,
- "Error Opening File",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error)
- End Try
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment