Tu peux utiliser un fichier XML.
J'avais ecrit cette pette classe il y a longtemps pour une application qui allait lire des parametres
Le fichier XML ressemblait a ca :
<?xml version="1.0" encoding="utf-8"?>
<options>
<dataSource path="E:\Developpement\CSharp\Exploitations\Options.xml" />
</options>
La classe :
using System;
using System.Xml;
using System.Windows.Forms;
namespace Exploitations
{
public class MyXml
{
private XmlDocument doc = null;
public MyXml(string file)
{
doc = new XmlDocument();
try
{
doc.Load(file);
}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("Le fichier " + file + " n'existe pas", "Erreur");
doc = null;
}
catch(Exception e)
{
MessageBox.Show(e.ToString(), "Erreur");
doc = null;
}
}
public string GetValue(string node, string attrib)
{
try
{
XmlNodeList list = doc.GetElementsByTagName(node);
return list.Item(0).Attributes[attrib].Value.ToString();
}
catch(Exception e)
{
MessageBox.Show(e.ToString(), "Erreur");
return "";
}
}
public void SetValue(string node, string attrib, string val)
{
try
{
if(doc != null)
{
XmlNodeList list = doc.GetElementsByTagName(node);
list.Item(0).Attributes[attrib].Value = val;
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString(), "Erreur");
}
}
public void Save(string path)
{
try
{
if(doc != null)
doc.Save(path);
}
catch(Exception e){MessageBox.Show(e.ToString(), "Erreur");}
}
public XmlDocument Doc
{
get{ return doc ;}
}
}
}
La lecture des options ainsi :
MyXml options = new MyXml(Application.StartupPath + @"\\Options.xml");
if(options.Doc != null)
{
startMAJ.Checked = bool.Parse(options.GetValue("autoUpdate", "updateWhenOpening"));
majTime.Text = options.GetValue("autoUpdate", "updateTimeInMinutes");
}
Et l'enregistrement des options
MyXml options = new MyXml(Application.StartupPath + @"\\Options.xml");
options.SetValue("autoUpdate", "updateWhenOpening", startMAJ.Checked.ToString());
options.SetValue("autoUpdate", "updateTimeInMinutes", majTime.Text);
options.Save(Application.StartupPath + @"\\Options.xml");
options = null;
Tu peux facilement l'optimiser pour ton utilisation :)
a++
Mx