Which configuration setting should you use?

You have created a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
The application, named EnterpriseApplication.exe, runs over the network.
You add the WindowSize parameter and the WindowPosition parameter to the Settings.settings file by using the designer at the User Scope Level.
The dimensions and position of the window are read from the user configuration file.
The application must retain the original window size and position for users executing the application.
You need to ensure that the following requirements are met:
* The window dimensions for each user are saved in the user configuration file.
* User settings persist when a user exits the application.
Which configuration setting should you use?

You have created a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
The application, named EnterpriseApplication.exe, runs over the network.
You add the WindowSize parameter and the WindowPosition parameter to the Settings.settings file by using the designer at the User Scope Level.
The dimensions and position of the window are read from the user configuration file.
The application must retain the original window size and position for users executing the application.
You need to ensure that the following requirements are met:
* The window dimensions for each user are saved in the user configuration file.
* User settings persist when a user exits the application.
Which configuration setting should you use?

A.
private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
Properties.Settings.Default.WindowPosition = new Point(this.Left, this.Top);
Properties.Settings.Default.WindowSize = new Size(this.Width, this.Height);
Properties.Settings.Default.Save();
}

B.
private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
RegistryKey appKey = Registry.CurrentUser.CreateSubKey("SoftwareEnterpriseApplication");
RegistryKey settingsKey = appKey.CreateSubKey("WindowSettings");
RegistryKey windowPositionKey = settingsKey.CreateSubKey("WindowPosition");
RegistryKey windowSizeKey = settingsKey.CreateSubKey("WindowSize");
windowPositionKey.SetValue("X", this.Left);
windowPositionKey.SetValue("Y", this.Top);
windowSizeKey.SetValue("Width", this.Width);
windowSizeKey.SetValue("Height", this.Height);
}

C.
private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load("EnterpriseApplication.exe.config");
System.Xml.XmlNode nodePosition = doc.SelectSingleNode("//setting[@name=’WindowPosition’]");
nodePosition.ChildNodes[0].InnerText = string.Format("{0},{1}", this.Left, this.Top);
System.Xml.XmlNode nodeSize = doc.SelectSingleNode("//setting[@name=’WindowSize’]");
nodeSize.ChildNodes[0].InnerText = string.Format("{0},{1}", this.Width, this.Height);
doc.Save("UserConfigDistractor2.exe.config");
}

D.
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
StreamWriter sw = new StreamWriter("EnterpriseApplication.exe.config", true);
sw.WriteLine("<EnterpriseApplication.Properties.Settings>");
sw.WriteLine("<setting name="WindowSize" serializeAs="String">");
sw.WriteLine(string.Format("<value>{0},{1}</value>", this.Width, this.Height));
sw.WriteLine("</setting>");
sw.WriteLine("<setting name="WindowPosition" serializeAs="String">");
sw.WriteLine(string.Format("<value>{0},{1}</value>", this.Left, this.Top));
sw.WriteLine("</setting>");
sw.WriteLine("</UserConfigProblem.Properties.Settings>");
sw.Close();
}



Leave a Reply 0

Your email address will not be published. Required fields are marked *