Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Namespace WindowsApplication16
{
Public partial class Form1: Form
{
String path = GetAppPath () + "PrintSet. ini ";
Public static string GetAppPath ()
{
String startupPath = Application. StartupPath;
If (! StartupPath. EndsWith (@"\"))
{
StartupPath = startupPath + @"\";
}
Return startupPath;
}
Public Form1 ()
{
InitializeComponent ();
}
[DllImport ("Kernel32")]
Public static extern bool WritePrivateProfileString
(
String section,
String key,
String val,
String filePath
);
[DllImport ("kernel32")]
Public static extern int GetPrivateProfileString
(
String section,
String key,
String def,
Byte [] retVal,
Int size,
String filePath
);
Public static string ReadString (string Section, string Ident, string Default, string FileName)
{
Byte [] Buffer = new Byte [65535];
Int bufLen = GetPrivateProfileString (Section, Ident, Default, Buffer, Buffer. GetUpperBound (0), FileName );
String s = Encoding. GetEncoding (0). GetString (Buffer );
S = s. Substring (0, bufLen );
Return s. Trim ();
}
Private void button2_Click (object sender, EventArgs e)
{
WritePrivateProfileString ("test", "test", "500", path );
WritePrivateProfileString ("test1", "test", "700", path );
}
Private void button#click (object sender, EventArgs e)
{
MessageBox. Show (Convert. ToString (ReadString ("test", "test", "200", path )));
}
}
}