![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| 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 | |||