Hello, Boniek!
In the first place, why do you need to load settings from an XML file?
You might have a reason, but if there is nothing specific, I would recommend
using Windows Registry.
It is a lot faster and way more convenient...
And you don't need to worry about all those nodes and crap...
Here is an example of using Registry Keys:
Microsoft.Win32.RegistryKey hkcu=
Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey regKey=
hkcu.CreateSubKey("Software\\Whatever your company name
is\\PortAccess");
//This will open a key if it exists or create one for you...
int x=
(int)regKey.GetValue(
"Value name goes here",
optional_default_value_is_here_if_VALUENAME_does_not_exist);
regKey.SetValue(
"Value name goes here",
data_goes_here_not_necessarily_a_string);
Here is my example:
private void MyForm_Load(object sender, System.EventArgs e)
{
Microsoft.Win32.RegistryKey hkcu=
Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey regKey=
hkcu.CreateSubKey("Software\\Maple Leaf Software\\PortAccess");
this.Left=(int)regKey.GetValue("My Window X", 10);
this.Top=(int)regKey.GetValue("My Window Y", 10);
}
private void MyForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
Microsoft.Win32.RegistryKey hkcu=
Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey regKey=
hkcu.CreateSubKey("Software\\Maple Leaf Software\\PortAccess");
regKey.SetValue("My Window X", this.Left);
regKey.SetValue("My Window Y", this.Top);
}
A better practice would actually be to create a private variable
hkcu or even regKey within a class and just use it when needed...
Also a very good thing to do would be create constant strings
containing messages like "My Window X", "My Window Y", etc.
To avoid errors, you know like when you set value for "Today"
and then somewhere in the program try to access "Tody" and
wonder why it is not working (believe me, it happens...)
Well, hope this helps.
Good luck.
You wrote on Mon, 29 Mar 2004 15:53:29 +0200:
B> I'm trying to do that because I want load a setting of toolBar from
B> file. The ToolBar has setting in xml and when it loaded this file my
B> form is repaing for any changes for that control. I want to disable my
B> form while toolbar is loading from file and set up my repainting for
B> that form. Setting of ToolBar was loaded by user and my toolbar change
B> setting for his bars. It don't looks good when my form flickes.
With best regards, Nurchi BECHED.