Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

Application Settings in VB.NET 2008

More Ways to Create an Application Setting

By Dan Mabbutt, About.com

Jan 27 2008

You can also create application settings using the Settings tab of the Project Designer window. This window is displayed if you select Properties under the Project menu or if you right-click the project in Solution Explorer and select Properties from the context menu. Here's a view showing what that looks like:

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

Remember to select System.Drawing.Color as the setting Type and select a color value in the Value column.

But you don't get quite the same result doing it this way. The setting isn't bound to the control (in this case, the Form) and you have to do that with code. (Event parameters are omitted to keep lines shorter.)

Private Sub Button1_Click( ...
   ColorDialog1.ShowDialog()
   My.Settings.MyBackColor = ColorDialog1.Color
   Me.BackColor = ColorDialog1.Color ' <- added
End Sub
Private Sub Form1_Load( ...
   Me.BackColor = My.Settings.MyBackColor ' <- added
End Sub

There is also one more feature. You can also generate a template Settings.vb file by clicking the View Code button. View Code, does more than just view the code. This button also generates the file to view. The helpful comments - see the illustration below - in the generated code tell you what you need to know. Just add the code for the event you need to handle in this window.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

The Settings tab of the Project Designer window is the only way to remove a setting, (select the row, right-click, and select Remove Setting).

Since the app.config file is a key part of this. The next page tells you how that works.

Explore Visual Basic

By Category

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. Application Settings in VB.NET 2008

©2009 About.com, a part of The New York Times Company.

All rights reserved.