JayBeeOH

TxtEditor - Apply & Save User Settings.

Apr 23rd, 2015
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.58 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2015. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Text Editor
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   Feb 2015
  16. '
  17. ' Description:    Simple plain text editor program with printing ability.
  18. '
  19. '                 Documentation is at:
  20. '                   App's screen image is at: http://imgur.com/TzWs9kO
  21. '                   App's screen design time specs at: http://pastebin.com/bhinRQ5d
  22. '                   App's Visual Basic .NET Apply & Save User Settings is at
  23. '                       http://pastebin.com/ycjj5dZK
  24. '                   App's Visual Basic .NET code is at http://pastebin.com/u/jaybeeoh
  25. '                   Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
  26. '-------------------------------------------------------------------------------------------
  27.  
  28. ' In Project's settings:
  29. '   Name        Type            Scope   Value
  30. '   FormSize    System.Drawing.Size User    0,0
  31. '   FormLocation    System.Drawing.Point    User    0,0
  32. '   ForeColor   System.Drawing.Color    User    Black
  33. '   Font        System.Drawing.Font User    Calibri, 12pt
  34.  
  35. #Region "  MainForm Events"
  36.  
  37.     ' Form loads and initialization performed.
  38.     Private Sub MainForm_Load(sender As Object, e As EventArgs) _
  39.         Handles MyBase.Load
  40.  
  41.     ' NOTE: Additional code not shown.
  42.  
  43.         ' Retrieve and apply user settings.
  44.         ApplySettings()
  45.  
  46.     End Sub
  47.  
  48.     ' Upon form closing, save user settings and check if document has changed.
  49.     Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) _
  50.         Handles Me.FormClosing
  51.  
  52.         SaveSettings()
  53.         If SaveChanges() Then
  54.             SaveToolStripMenuItem_Click(sender, e)
  55.         End If
  56.     End Sub
  57.  
  58. #End Region
  59.  
  60.  
  61. #Region " Settings"
  62.  
  63. #Region " ApplySettings"
  64.  
  65.     Private Sub ApplySettings()
  66.  
  67.         If My.Settings.FormSize <> Drawing.Size.Empty Then
  68.             Me.Size = My.Settings.FormSize
  69.         End If
  70.  
  71.         If My.Settings.FormLocation <> Drawing.Point.Empty Then
  72.             Me.Location = My.Settings.FormLocation
  73.         End If
  74.  
  75.         If My.Settings.ForeColor <> System.Drawing.Color.Empty Then
  76.             MyTextBox.ForeColor = My.Settings.ForeColor
  77.         End If
  78.  
  79.         If (My.Settings.Font.Name <> String.Empty) AndAlso (My.Settings.Font.Size <> 0) Then
  80.             MyTextBox.Font = My.Settings.Font
  81.         End If
  82.     End Sub
  83.  
  84. #End Region
  85.  
  86. #Region " SaveSettings"
  87.  
  88.     Private Sub SaveSettings()
  89.  
  90.         If Me.WindowState = FormWindowState.Normal Then
  91.             My.Settings.FormSize = Me.Size
  92.         Else
  93.             ' If the form was maximized or minimized,
  94.             ' return to the restore state
  95.             My.Settings.FormSize = Me.RestoreBounds.Size
  96.         End If
  97.  
  98.         My.Settings.FormLocation = Me.Location
  99.         My.Settings.ForeColor = MyTextBox.ForeColor
  100.         My.Settings.Font = MyTextBox.Font
  101.         My.Settings.Save()
  102.     End Sub
  103.  
  104. #End Region
  105.  
  106. #End Region
Advertisement
Add Comment
Please, Sign In to add comment