The WinForms Notepad Project: More Settings, About Box Basics (Premium)

OK, I have time for two more small but fun changes: We can persist all of the user’s settings changes and add a starter About box.

First up, those settings.
Save and restore more settings
In the previous installment, we learned how to use application settings to save the size and location of the application window when it closes and then restore those settings when it’s run again. But these aren’t the only application settings we’ll want to persist: We need to do similarly for the configured font, whether the status bar is visible, and whether word-wrap is enabled.

To get started, we may as well just add three application settings, one for each of those settings. So open up application settings (right-click the project in Solution Explorer and choose Properties) and navigate to the Settings tab.

Add the following settings:

MyFont. Type is System.Drawing.Font.

MyStatusBar. Type is Boolean.

MyWordWrap. Type is Boolean.

Now, close application settings, saving as prompted, and locate the Form1_Closing event handler in Form1.vb. We had added two lines of code related to settings right at the top of this event handler. Open a new line between those two lines and add the following:
My.Settings.MyFont = TextBox1.Font
My.Settings.MyStatusBar = StatusStrip1.Visible
My.Settings.MyWordWrap = WordWrapToolStripMenuItem.Checked
Next, locate the Form1_Load event handler. Here, again, we need to add code related to those settings, but in reverse: This time we’re reading the saved values in application settings and applying them to the relevant properties of the affected controls. But we also need to change the Checked property for the menu items related to the status bar being displayed and word-wrap being enabled. So, after the If-Then block about the MySize application setting, add the following lines of code:
TextBox1.Font = My.Settings.MyFont
StatusStrip1.Visible = My.Settings.MyStatusBar
StatusBarToolStripMenuItem.Checked = My.Settings.MyStatusBar
TextBox1.WordWrap = My.Settings.MyWordWrap
WordWrapToolStripMenuItem.Checked = My.Settings.MyWordWrap
And that should do it. If you test the application, all of the settings changes you make---to the font, the word wrap, and the status bar, in addition to the window size and location---should all persist when you run the application again after closing it. And the Format > Word Wrap and View > Status Bar menu items should be checked (or not) correctly each time the application runs too.
About box beginnings
We will build this out a bit more later, but adding a basic About box to our application is easy, since Windows Forms and Visual Studio offer a pre-fab About box we can use.

To get started, first add the About NotePadWF menu item under Help. This should be familiar ground: Just be sure to set the Text property to “&About NotePadWF” (no quotes).

Then, we need to add an About Box, which is a second form window, to our project. To do th...

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Please check our Community Guidelines before commenting

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC