We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to configure State Persistence for RadialGauge control?

Platform: WinForms |
Control: General |
.NET Framework: 4

State Persistence support helps end users to save the application / controls customization based on their needs. So, it is a very essential feature and some controls may not have support to Serialize and Deserialize its customization settings by built-in.  This article will provide guidance to configure State Persistence for those controls in sample application level. 

 

For example

 

Here we have considered RadialGauge control. At present RadialGauge doesn’t have built-in State Persistence support and its property information can be programmatically saved / load from XML by following below steps.

 

Step 1: Define Class that helps Serialize / De-Serialize RadialGauge property details and mark it as XMLRoot attribute.

Step 2: Implement required properties of RadialGauge that needs to be Serialized / De-Serialized in this class and mark it as XMLElement attribute.

Step 3: Save those properties using XMLTextWriter class, that helps to store information in XML file.

Step 4: Load those properties using XMLTextReader class, that helps to retrieve information from XML file.

 

For example

 

Here, we have Serialized / Deserialized the “Value” and “VisualStyle” properties of RadialGauge control.

 

The following code demonstrates the same.

 

Code Example: [C#]

 

 
//codes in form1.cs
 
 
//Save RadialGauge state
 
SaveRadialGaugeProperties("GaugeFile");
 
//load
LoadRadialGaugeProperties("GaugeFile");
 
//For Save
 
public void SaveRadialGaugeProperties(string filename)
{
 
string path = @"\" + filename;
 
List<RadialGaugeAdvSettings> settingsList = new List<RadialGaugeAdvSettings>();
 
RadialGaugeAdvSettings s_settings = new RadialGaugeAdvSettings();
 
s_settings.Value = this.radialGauge1.Value;
 
s_settings.VisualStyle = this.radialGauge1.VisualStyle;
 
settingsList.Add(s_settings);
 
using (XmlTextWriter writer = new XmlTextWriter(Environment.CurrentDirectory + path, Encoding.UTF8))
{
 
writer.Formatting = Formatting.Indented;
 
XmlSerializer serializer = new XmlSerializer(typeof(List<RadialGaugeAdvSettings>));
 
serializer.Serialize(writer, settingsList);
 
}
}
 
//For load
public void LoadRadialGaugeProperties(string filename)
{
 
string path = @"\" + filename;
 
if (File.Exists(filename))
{
 
FileStream stream = new FileStream((Environment.CurrentDirectory + path), FileMode.Open);
 
XmlTextReader reader = new XmlTextReader(stream);
 
XmlSerializer serializer = new XmlSerializer(typeof(List<RadialGaugeAdvSettings>));
 
List<RadialGaugeAdvSettings> savedsettings =
 
(List<RadialGaugeAdvSettings>)serializer.Deserialize(reader);
 
foreach (var settings in savedsettings)
{
 
this.radialGauge1.Value = settings.Value;
 
this.radialGauge1.VisualStyle = settings.VisualStyle;
 
}
}
}
 
//Codes in RadialGaugeAdv.cs
 
[XmlRoot("Root")]
 
public class RadialGaugeAdvSettings
{
 
[XmlElement("Value")]
 
public float Value
{
 
get;
 
set;
 
}
[XmlElement("VisualStyle")]
 
public ThemeStyle VisualStyle
{
 
get;
 
set;
 
}
 
}
 

 

Code Example: [VB]

 

'Codes in Form1.vb
 
'Save RadialGauge state
 
SaveRadialGaugeProperties("GaugeFile")
 
'load
 
LoadRadialGaugeProperties("GaugeFile")
 
'For Save
 
Public Sub SaveRadialGaugeProperties(ByVal filename As String)
 
Dim path As String = "\" & filename
 
Dim settingsList As New List(Of RadialGaugeAdvSettings)()
 
Dim s_settings As New RadialGaugeAdvSettings()
 
s_settings.Value = Me.radialGauge1.Value
 
s_settings.VisualStyle = Me.radialGauge1.VisualStyle
 
settingsList.Add(s_settings)
 
Using writer As New XmlTextWriter(Environment.CurrentDirectory & path, Encoding.UTF8)
 
writer.Formatting = Formatting.Indented
 
Dim serializer As New XmlSerializer(GetType(List(Of RadialGaugeAdvSettings)))
 
serializer.Serialize(writer, settingsList)
 
End Using
 
End Sub
 
'For load
 
Public Sub LoadRadialGaugeProperties(ByVal filename As String)
 
Dim path As String = "\" & filename
 
If File.Exists(filename) Then
 
Dim stream As New FileStream((Environment.CurrentDirectory & path), FileMode.Open)
 
Dim reader As New XmlTextReader(stream)
 
Dim serializer As New XmlSerializer(GetType(List(Of RadialGaugeAdvSettings)))
 
Dim savedsettings As List(Of RadialGaugeAdvSettings) =
 
DirectCast(serializer.Deserialize(reader), List(Of RadialGaugeAdvSettings))
 
For Each settings In savedsettings
 
Me.radialGauge1.Value = settings.Value
 
Me.radialGauge1.VisualStyle = settings.VisualStyle
 
Next settings
 
End If
 
End Sub
 
'Codes in RadialGaugeAdv.vb
 
<XmlRoot("Root")>
 
Public Class RadialGaugeAdvSettings
 
<XmlElement("Value")>
 
Public Property Value() As Single
 
<XmlElement("VisualStyle")>
 
Public Property VisualStyle() As ThemeStyle
 
End Class

 

Sample

 

C#:  RadialGaugeSerializationSample

 

VB:  RadialGaugeSerializationSample

 

 

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile