Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Storing and accessing application settings

 
 
Old 01-31-2006   #1 (permalink)
fö


 
 

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


 
 

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ö


 
 

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


 
 

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ö


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
Accessing Windows application from Web application? .NET General
Application Settings user settings storage directory .NET General
Accessing documents & settings Vista General
ASP application accessing a C++ COM DLL is giving security error. Vista General
ASP application accessing a C++ COM DLL is giving security error. Vista security


Vista Forums 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 Ltd

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