so what I have is a layout that will take the info that is added into a textbox and then add it to an INI file. Everything there works fine but when the form is reopened I want it to read what is in the INI file and display it into the proper textboxs.
I have looked around and finding nothing but it could be the way I am looking too. Have tried the textbox.items.add(inif.Read("Database", "Devs")); with no luck.
my code is as follows
Thanks
I have looked around and finding nothing but it could be the way I am looking too. Have tried the textbox.items.add(inif.Read("Database", "Devs")); with no luck.
my code is as follows
Thanks
set ini:
public partial class DashBoard : Form
{
public DashBoard()
{
InitializeComponent();
}
private void DashBoard_Load(object sender, EventArgs e)
{
}
private void updatebtn_Click(object sender, EventArgs e)
{
string siten = sitetxtbox.Text;
sitetxtbox.Text = "siten";
string personto = emailtotxtbox.Text;
sitetxtbox.Text = "personto";
string ccto = cctotxtbox.Text;
sitetxtbox.Text = "ccto";
string bcto = bcctextbox.Text;
sitetxtbox.Text = "bcto";
INIFile inif = new INIFile(@"c:\test\mailsettings.ini");
inif.Write("Properties", "site", $"{siten}");
inif.Write("Properties", "personto", $"{personto}");
inif.Write("Properties", "ccto", $"{ccto}");
inif.Write("Properties", "bcto", $"{bcto}");
MessageBox.Show("Settings Have Been Updated");
}
}
}
class INIFile
{
private string filePath;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key,
string val,
string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key,
string def,
StringBuilder retVal,
int size,
string filePath);
public INIFile(string filePath)
{
this.filePath = filePath;
}
public void Write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value.ToLower(), this.filePath);
}
public string Read(string section, string key)
{
StringBuilder SB = new StringBuilder(255);
int i = GetPrivateProfileString(section, key, "", SB, 255, this.filePath);
return SB.ToString();
}
public string FilePath
{
get { return this.filePath; }
set { this.filePath = value; }
}
)
Last edited: