You should better use a class specially for settings. This class must be
Serializable
This is an exapmle that saves and retrievs the setting for the font size of
a textBox in a file
-----------Settings Class---------------
using System;
[Serializable]
public class settingsClass
{
public settingsClass(f loat size,int delay)
{
fontSize=size;
programDelay=de lay;
}
#region Font Size
private float fontSize;
public float FontSize
{
get
{
return fontSize;
}
set
{
fontSize=value;
}
}
#endregion Font Size
}
-----------loadSaveSetting sClass--------------------------------
using System.IO;
using System.Drawing;
using System.Runtime. Serialization.F ormatters.Binar y;
public class loadSaveSetting sClass
{
public loadSaveSetting sClass(main mf)
{
mainForm=mf;
}
private static main mainForm;
private static BinaryFormatter binaryFormatter = new BinaryFormatter ();
private static FileStream fileStream;
private static settingsClass settings;
#endregion ???????? ??????????
public static void loadSettings()
{
settings=new settingsClass(0 ,0);
string fileName=(strin g)mainForm.Prog ramDirectory+"\ \settings.dat";
try
{
fileStream=new FileStream(file Name,FileMode.O pen,FileAccess. Read);
settings=(setti ngsClass) binaryFormatter .Deserialize(fi leStream);
}
catch (System.IO.File NotFoundExcepti on)
{
return;
}
catch (System.Runtime .Serialization. SerializationEx ception)
{
fileStream.Clos e();
return;
}
fileStream.Clos e();
mainForm.source Code.Font=new
Font(mainForm.s ourceCode.Font. FontFamily,sett ings.FontSize);
}
public static void saveSettings()
{
settings = new
settingsClass(m ainForm.sourceC ode.Font.Size,m ainForm.delayTr ackBar.Value);
string fileName=(strin g)mainForm.Prog ramDirectory+"\ \settings.dat";
fileStream=new
FileStream(file Name,FileMode.O penOrCreate,Fil eAccess.Write);
binaryFormatter .Serialize(file Stream,settings );
fileStream.Clos e();
}
#endregion Save Setting
}
"Shane Mergy" <mo***@ameritec h.net> wrote in message
news:41******** *************** ***@posting.goo gle.com...
i have a program that reads through an ini file and does stuff so far
the only thing i am having trouble with is the writing to the ini
file. if the section is alreadey there i want to do a search for that
line then all text to the next line of end of that block can someone
help with this.