C# Custom user settings class not saving
Posted
by Zenox
on Stack Overflow
See other posts from Stack Overflow
or by Zenox
Published on 2009-09-24T22:42:38Z
Indexed on
2010/05/29
17:22 UTC
Read the original article
Hit count: 150
I have the following class:
[Serializable]
[XmlRoot ( ElementName = "TextData", IsNullable = false)]
public class TextData
{
private System.Drawing.Font fontColor;
[XmlAttribute ( AttributeName = "Font" )]
public System.Drawing.Font Font { get; set; }
[XmlAttribute ( AttributeName = "FontColor" )]
public System.Drawing.Color FontColor { get; set; }
[XmlAttribute ( AttributeName = "Text" )]
public string Text { get; set; }
public TextData ( )
{
} // End of TextData
} // End of TextData
And Im attempting to save it with the following code:
// Create our font dialog
FontDialog fontDialog = new FontDialog ( );
fontDialog.ShowColor = true;
// Display the dialog and check for an ok
if ( DialogResult.OK == fontDialog.ShowDialog ( ) )
{
// Save our changes for the font settings
if ( null == Properties.Settings.Default.MainHeadlineTextData )
{
Properties.Settings.Default.MainHeadlineTextData = new TextData ( );
}
Properties.Settings.Default.MainHeadlineTextData.Font = fontDialog.Font;
Properties.Settings.Default.MainHeadlineTextData.FontColor = fontDialog.Color;
Properties.Settings.Default.Save ( );
}
Everytime I load the the application, the Properties.Settings.Default.MainHeadlineTextData is still null. Saving does not seem to take effect. I read on another post that the class must be public and it is. Any ideas why this would not be working properly?
© Stack Overflow or respective owner