Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 4 comments about this article.
Article source: CoDe (2006 - Jul/Aug)


Article Pages:  1  2 3 - Next >


Retaining Multiple Sets of User Settings

Retaining a single set of user settings for your application is easy.Retaining multiple sets of user settings is much more challenging.

Many Windows applications allow the user to define preferences that customize the application’s appearance and behavior. One of the most common examples of user customizations is the ability to move and resize a form. The user can move or resize a form and then exit the application. When the user opens the application again, the form is restored to the last user-defined position and size.

"
The SettingsKey is the key feature that allows you to have multiple sets of settings.
"

The new settings feature in Visual Studio 2005 provides a very easy way to store these user preferences upon exit of the application and restore them when the user opens the application again. But these simple techniques only support one set of named settings. So if you have 20 forms in your application, do you need 20 named settings for the form location and 20 named settings for the form size? Luckily, the answer is no. With a little more work you can retain multiple sets of user settings.

This article first reviews the fundamentals of user settings. It then details how to work with multiple sets of user settings.

User Settings Fundamentals

A common user request is for your application to remember its state so that the application can be returned to that state when the user runs the application again. For example, if the user laid out the windows of the application in a specific manner and then closed the windows, the user expects that the windows will be returned to their last defined locations and sizes when they are reopened.

Visual Studio 2005 added a Settings tab on the Project Designer window to support the management of application settings. Application settings allow you to store and retrieve property settings and other information for your application. You can use application settings to maintain custom application settings and end-user preferences.

You can use this feature for application settings that you don’t want hard-coded into the application, such as your connection string. You can also use this feature to store end-user preferences such as form size and location and color choices. In either case, application settings are available within the code of your application using the My.Settings object.

To define an application setting:

  1. Determine which application and user settings you wish to retain. For example, you may want to save the form size and location.
  2. Open the Project Designer for the Windows Application project.
  3. Select the Settings tab.
  4. In the Name column, enter the name of the setting. Each setting must have a unique name. For example, use FormLocation to define a setting for the location of the form and FormSize for the size.
  5. In the Type column, select the appropriate data type for the setting. You can select any data type that can be converted to a string.
  6. In the Scope column, define the scope: User or Application. Select User scope to define a setting that is saved for each user at runtime. Select Application scope to define a setting that is saved for the application.
  7. Define any default value in the Value column.

The result is shown in Figure 1.

Click for a larger version of this image.

Figure 1: The Settings tab of the Project Designer allows you to define user preference and application settings.

There are some application settings, such as form location, that can be bound directly to a property of a form or control at design time. For Visual Basic applications, the runtime automatically stores the setting before the form is closed and automatically restores the setting when the form is opened again.

To bind a setting to a property of a form or control at design time:

  1. Display the Properties window for the form or control.
  2. Open the (Application Settings) property in the Properties window.
  3. Map the desired property to the defined setting as shown in Figure 2.

Click for a larger version of this image.

Figure 2: The ApplicationSettings properties allow you to bind a setting to a specific form or control property.

Notice in Figure 2 that there are only two form properties that can be bound to user settings at design time. All other user settings must be set and restored in the code. The form size cannot be bound directly to a property because it requires additional code to handle the maximized and minimized case.

&

By: Deborah Kurata

Deborah Kurata is cofounder of InStep Technologies Inc., a professional consulting firm that focuses on turning your business vision into reality using Microsoft .NET technologies. She has over 15 years of experience in architecting, designing and developing successful applications.

Deborah is the author of several books, including Best Kept Secrets in .NET (Apress), Doing Objects in Visual Basic 6.0 (SAMS) and Doing Web Development: Client-Side Techniques (Apress). She is on the INETA Speaker’s Bureau, is a well-known speaker at technical conferences, and is a Microsoft Most Valuable Professional (MVP). After a hard day of coding and taking care of her family, Deborah enjoys blowing stuff up (on her XBox of course).

Some of the information in this article was obtained from her upcoming book, Doing Objects in VB 2005.

deborahk@insteptech.com

Fast Facts

Users want their forms to be in the same position the next time they open their application. While Visual Studio 2005 out of the box provides a way to store one set of named settings, there is a way to store more.



Article Pages:  1  2 3 - Next Page: 'Retaining Multiple Sets of User Settings (con't)' >>

Page 1: Retaining Multiple Sets of User Settings
Page 2: Retaining Multiple Sets of User Settings (con't)
Page 3: Retaining Multiple Sets of User Settings (con't)

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.7 out of 5

17 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      AppsWorld Europe

 

SSWUG