namespace WindowsApplication1
{
public partial class Form1 : Form
{
[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);
//对INI文件写操作
public void IniWriteValue(string Section, string Key, string Value, string filepath)
{
WritePrivateProfileString(Section, Key, Value, filepath);
}
public Form1()
{
InitializeComponent();
}
//对INI文件读操作
public string IniReadValue(string Section, string Key, string filepath)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, filepath);
return temp.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}
//读取INI文件
private void button1_Click(object sender, EventArgs e)
{
string path1 = Directory.GetCurrentDirectory().ToString();
this.textBox1.Text = IniReadValue("ODBC 32 bit Data Source", "MS Access Database", path1 + "\\555.ini");
}
//写入INI文件
private void button2_Click(object sender, EventArgs e)
{
string path1 = Directory.GetCurrentDirectory().ToString();
IniWriteValue("ODBC 32 bit Data Source", "MS Access Database", this.textBox1.Text, path1+"\\555.ini");
MessageBox.Show(path1);
}
}
}
浙公网安备 33010602011771号