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(float size,int delay)
{
fontSize=size;
programDelay=delay;
}
#region Font Size
private float fontSize;
public float FontSize
{
get
{
return fontSize;
}
set
{
fontSize=value;
}
}
#endregion Font Size
}
-----------loadSaveSettingsClass--------------------------------
using System.IO;
using System.Drawing;
using System.Runtime.Serialization.Formatters.Binary;
public class loadSaveSettingsClass
{
public loadSaveSettingsClass(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=(string)mainForm.ProgramDirectory+"\\sett ings.dat";
try
{
fileStream=new FileStream(fileName,FileMode.Open,FileAccess.Read) ;
settings=(settingsClass) binaryFormatter.Deserialize(fileStream);
}
catch (System.IO.FileNotFoundException)
{
return;
}
catch (System.Runtime.Serialization.SerializationExcepti on)
{
fileStream.Close();
return;
}
fileStream.Close();
mainForm.sourceCode.Font=new
Font(mainForm.sourceCode.Font.FontFamily,settings. FontSize);
}
public static void saveSettings()
{
settings = new
settingsClass(mainForm.sourceCode.Font.Size,mainFo rm.delayTrackBar.Value);
string fileName=(string)mainForm.ProgramDirectory+"\\sett ings.dat";
fileStream=new
FileStream(fileName,FileMode.OpenOrCreate,FileAcce ss.Write);
binaryFormatter.Serialize(fileStream,settings);
fileStream.Close();
}
#endregion Save Setting
}
"Shane Mergy" <mo***@ameritech.net> wrote in message
news:41**************************@posting.google.c om...
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.