Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Storing and accessing application settings

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-31-2006   #1 (permalink)
fö
Guest


 

Storing and accessing application settings

I want to store the location and size of my application window
when the app closes and reuse this information when the app
is started again. How can I do this?
This is what my app code looks like:

public class MyApp : Application
{
protected override void OnStartup(StartupEventArgs e)
{
MyWin win = new MyWin();

win.Left = 222;
win.Top = 111;
win.Width = 666;
win.Height = 444;

win.Show();
}
}

Instead of having the fixed numbers I want to read them
from a location where they are stored when the app closes.

Thanks,
fö


My System SpecsSystem Spec
Old 01-31-2006   #2 (permalink)
viliescu
Guest


 

RE: Storing and accessing application settings

You can use the new application settings concept from .NET 2.0

You add to the project settings the window parameters (four doubles or a
rectangle),
at startup you read the values, at shutdown you save the values.

For example, right-click the project -> Properties -> Settings
Add 4 settings (WindowLeft, WindowTop, WindowWidth, WindowHeight) of type
double, scope User and some default values.

On startup:
win.Left = Settings.Default.WindowLeft;
win.Top = Settings.Default.WindowTop;
....

On shutdown or when the window is closed:
Settings.Default.WindowLeft = win.Left;
Settings.Default.WindowTop = win.Top;
....
Settings.Default.Save();

--
Valentin Iliescu [MVP C#]


"fö" wrote:

> I want to store the location and size of my application window
> when the app closes and reuse this information when the app
> is started again. How can I do this?
> This is what my app code looks like:
>
> public class MyApp : Application
> {
> protected override void OnStartup(StartupEventArgs e)
> {
> MyWin win = new MyWin();
>
> win.Left = 222;
> win.Top = 111;
> win.Width = 666;
> win.Height = 444;
>
> win.Show();
> }
> }
>
> Instead of having the fixed numbers I want to read them
> from a location where they are stored when the app closes.
>
> Thanks,
> fö
>

My System SpecsSystem Spec
Old 01-31-2006   #3 (permalink)
fö
Guest


 

RE: Storing and accessing application settings

Hi Valentin,

well that sounds real good, but it doesn't work!
The compiler does not know the type "Settings"
(I suppose it should be in namespace System.Configuration).
Furthermore the Dec CTP SDK Documentation does not know
a Settings class.

In addition the SDK documents a class ConfigurationManager
which should have an AppSettings property of type
AppSettingsSection (all included in System.Configuration).
But even these types are not known by the compiler.

So what's going wrong?

Thanks.

"viliescu" wrote:

> You can use the new application settings concept from .NET 2.0
>
> You add to the project settings the window parameters (four doubles or a
> rectangle),
> at startup you read the values, at shutdown you save the values.
>
> For example, right-click the project -> Properties -> Settings
> Add 4 settings (WindowLeft, WindowTop, WindowWidth, WindowHeight) of type
> double, scope User and some default values.
>
> On startup:
> win.Left = Settings.Default.WindowLeft;
> win.Top = Settings.Default.WindowTop;
> ...
>
> On shutdown or when the window is closed:
> Settings.Default.WindowLeft = win.Left;
> Settings.Default.WindowTop = win.Top;
> ...
> Settings.Default.Save();
>
> --
> Valentin Iliescu [MVP C#]
>
>
> "fö" wrote:
>
> > I want to store the location and size of my application window
> > when the app closes and reuse this information when the app
> > is started again. How can I do this?
> > This is what my app code looks like:
> >
> > public class MyApp : Application
> > {
> > protected override void OnStartup(StartupEventArgs e)
> > {
> > MyWin win = new MyWin();
> >
> > win.Left = 222;
> > win.Top = 111;
> > win.Width = 666;
> > win.Height = 444;
> >
> > win.Show();
> > }
> > }
> >
> > Instead of having the fixed numbers I want to read them
> > from a location where they are stored when the app closes.
> >
> > Thanks,
> > fö
> >

My System SpecsSystem Spec
Old 01-31-2006   #4 (permalink)
viliescu
Guest


 

RE: Storing and accessing application settings

Settings class is not in .Net libraries but is created automatically in the
project (look in Solution Explorer for Properties directory and you will find
the Settings.Designer.cs file).
It is defined in MyProject.Properties namespace (if "MyProject" is the name
of the project) so you'll have to import it.
--
Valentin Iliescu [MVP C#]


"fö" wrote:

> Hi Valentin,
>
> well that sounds real good, but it doesn't work!
> The compiler does not know the type "Settings"
> (I suppose it should be in namespace System.Configuration).
> Furthermore the Dec CTP SDK Documentation does not know
> a Settings class.
>
> In addition the SDK documents a class ConfigurationManager
> which should have an AppSettings property of type
> AppSettingsSection (all included in System.Configuration).
> But even these types are not known by the compiler.
>
> So what's going wrong?
>
> Thanks.
>
> "viliescu" wrote:
>
> > You can use the new application settings concept from .NET 2.0
> >
> > You add to the project settings the window parameters (four doubles or a
> > rectangle),
> > at startup you read the values, at shutdown you save the values.
> >
> > For example, right-click the project -> Properties -> Settings
> > Add 4 settings (WindowLeft, WindowTop, WindowWidth, WindowHeight) of type
> > double, scope User and some default values.
> >
> > On startup:
> > win.Left = Settings.Default.WindowLeft;
> > win.Top = Settings.Default.WindowTop;
> > ...
> >
> > On shutdown or when the window is closed:
> > Settings.Default.WindowLeft = win.Left;
> > Settings.Default.WindowTop = win.Top;
> > ...
> > Settings.Default.Save();
> >
> > --
> > Valentin Iliescu [MVP C#]
> >
> >
> > "fö" wrote:
> >
> > > I want to store the location and size of my application window
> > > when the app closes and reuse this information when the app
> > > is started again. How can I do this?
> > > This is what my app code looks like:
> > >
> > > public class MyApp : Application
> > > {
> > > protected override void OnStartup(StartupEventArgs e)
> > > {
> > > MyWin win = new MyWin();
> > >
> > > win.Left = 222;
> > > win.Top = 111;
> > > win.Width = 666;
> > > win.Height = 444;
> > >
> > > win.Show();
> > > }
> > > }
> > >
> > > Instead of having the fixed numbers I want to read them
> > > from a location where they are stored when the app closes.
> > >
> > > Thanks,
> > > fö
> > >

My System SpecsSystem Spec
Old 01-31-2006   #5 (permalink)
fö
Guest


 

RE: Storing and accessing application settings

Thanks, it works!

"viliescu" wrote:

> Settings class is not in .Net libraries but is created automatically in the
> project (look in Solution Explorer for Properties directory and you will find
> the Settings.Designer.cs file).
> It is defined in MyProject.Properties namespace (if "MyProject" is the name
> of the project) so you'll have to import it.
> --
> Valentin Iliescu [MVP C#]
>
>
> "fö" wrote:
>
> > Hi Valentin,
> >
> > well that sounds real good, but it doesn't work!
> > The compiler does not know the type "Settings"
> > (I suppose it should be in namespace System.Configuration).
> > Furthermore the Dec CTP SDK Documentation does not know
> > a Settings class.
> >
> > In addition the SDK documents a class ConfigurationManager
> > which should have an AppSettings property of type
> > AppSettingsSection (all included in System.Configuration).
> > But even these types are not known by the compiler.
> >
> > So what's going wrong?
> >
> > Thanks.
> >
> > "viliescu" wrote:
> >
> > > You can use the new application settings concept from .NET 2.0
> > >
> > > You add to the project settings the window parameters (four doubles or a
> > > rectangle),
> > > at startup you read the values, at shutdown you save the values.
> > >
> > > For example, right-click the project -> Properties -> Settings
> > > Add 4 settings (WindowLeft, WindowTop, WindowWidth, WindowHeight) of type
> > > double, scope User and some default values.
> > >
> > > On startup:
> > > win.Left = Settings.Default.WindowLeft;
> > > win.Top = Settings.Default.WindowTop;
> > > ...
> > >
> > > On shutdown or when the window is closed:
> > > Settings.Default.WindowLeft = win.Left;
> > > Settings.Default.WindowTop = win.Top;
> > > ...
> > > Settings.Default.Save();
> > >
> > > --
> > > Valentin Iliescu [MVP C#]
> > >
> > >
> > > "fö" wrote:
> > >
> > > > I want to store the location and size of my application window
> > > > when the app closes and reuse this information when the app
> > > > is started again. How can I do this?
> > > > This is what my app code looks like:
> > > >
> > > > public class MyApp : Application
> > > > {
> > > > protected override void OnStartup(StartupEventArgs e)
> > > > {
> > > > MyWin win = new MyWin();
> > > >
> > > > win.Left = 222;
> > > > win.Top = 111;
> > > > win.Width = 666;
> > > > win.Height = 444;
> > > >
> > > > win.Show();
> > > > }
> > > > }
> > > >
> > > > Instead of having the fixed numbers I want to read them
> > > > from a location where they are stored when the app closes.
> > > >
> > > > Thanks,
> > > > fö
> > > >

My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Windows application from Web application? its_faiz .NET General 0 07-09-2008 08:04 AM
Application Settings user settings storage directory Chris Crowther MBCS .NET General 5 04-09-2008 04:02 AM
Accessing Firewall settings from WMI Keith Hill PowerShell 6 04-24-2007 02:31 PM
ASP application accessing a C++ COM DLL is giving security error. John Vista General 0 08-03-2006 07:51 AM
ASP application accessing a C++ COM DLL is giving security error. John Vista security 0 08-03-2006 07:50 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51