最好详细写下`有个大体框架
解决方案 »
- 找不到类型或命名空间名称“PropertyPage”(是否缺少 using 指令或程序集引用)
- 类别设置样式问题!
- 微软.net快速入门教程里的例子怎么都没关闭SqlConnection??
- 有开发过数据绑定控件的进!!!
- 高分请教线程中数据库连结的问题!
- C#连入ACCESS数据库的问题,麻烦了
- 一个FORM分两个区域,左边一个是一个Tree,如何在选中某一个节点后,让右边区域全部改掉,也就是换成另外一个控件.
- 谁做个试验?就是用程序登陆www.ebay.com.cn。附送www访问类,支持Cookies和引用,代理,验证等。成功的100分。
- 在线等,一个滑块控件如何在设计期就能够滑动设计值(不是运行期!)???
- C#如何打包
- 遍历的小问题
- 为什么用了多线程.用户界面还是一样没有响应
[DllImport("kernel32")]
private static extern bool GetProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize);
[DllImport("kernel32")]
private static extern bool WriteProfileString(string lpApplicationName, string lpKeyName, string lpString);
#endregion private void button1_Click(object sender, EventArgs e)
{
//写入Win.ini文件
try
{
WriteProfileString("演示程序", "软件名称", this.textBox1.Text);
WriteProfileString("演示程序", "著作权人", this.textBox2.Text);
WriteProfileString("演示程序", "版本号", this.textBox3.Text);
MessageBox.Show("写入Win.ini文件操作成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception Err)
{
MessageBox.Show("写入Win.ini文件操作失败!" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} private void button2_Click(object sender, EventArgs e)
{
//读取Win.ini文件
StringBuilder MyString = new StringBuilder(256);
GetProfileString("演示程序", "软件名称", "", MyString, 256);
this.textBox1.Text = MyString.ToString();
GetProfileString("演示程序", "著作权人", "", MyString, 256);
this.textBox2.Text = MyString.ToString();
GetProfileString("演示程序", "版本号", "", MyString, 256);
this.textBox3.Text = MyString.ToString();
}
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern long GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int Size, string filePath);
private static void Wini(string Section, string Key, string Val, string FilePath)
{
WritePrivateProfileString(Section, Key, Val, FilePath);
}
private static string Rini(string Section, string Key, string Val, string FilePath)
{
int X = Convert.ToInt32(Val);
StringBuilder Str = new StringBuilder(X);
GetPrivateProfileString(Section, Key, "Error", Str, X, FilePath);
return Str.ToString();
}
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Security.Cryptography; namespace INI{
public class INIHelper
{
private string strKey = "CSDN@#*&";
public string inipath;
[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);
/// <summary>
/// 构造方法
/// </summary>
/// <param name="INIPath">文件路径</param>
public INIClass(string INIPath)
{
inipath = INIPath;
}
/// <summary>
/// 写入INI文件
/// </summary>
/// <param name="Section">项目名称(如 [TypeName] )</param>
/// <param name="Key">键</param>
/// <param name="Value">值</param>
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.inipath);
} /// <summary>
/// Md5加密写入INI文件
/// </summary>
/// <param name="Section">项目名称(如 [TypeName] )</param>
/// <param name="Key">键</param>
/// <param name="Value">值</param>
public void IniMd5WriteValue(string Section, string Key, string Value)
{
string str = MD5Encrypt(Value, strKey);
WritePrivateProfileString(Section, Key, str, this.inipath);
} /// <summary>
/// 读出INI文件
/// </summary>
/// <param name="Section">项目名称(如 [TypeName] )</param>
/// <param name="Key">键</param>
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(500);
int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.inipath);
return temp.ToString();
} /// <summary>
/// 读出INI文件
/// </summary>
/// <param name="Section">项目名称(如 [TypeName] )</param>
/// <param name="Key">键</param>
public string IniMd5ReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(500);
int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.inipath);
string str = temp.ToString(); return MD5Decrypt(str, strKey);
} /// <summary>
/// 验证文件是否存在
/// </summary>
/// <returns>布尔值</returns>
public bool ExistINIFile()
{
return File.Exists(inipath);
} ///MD5加密
public string MD5Encrypt(string pToEncrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
} ///MD5解密
public string MD5Decrypt(string pToDecrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider(); byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
for (int x = 0; x < pToDecrypt.Length / 2; x++)
{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
} des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock(); StringBuilder ret = new StringBuilder(); return System.Text.Encoding.Default.GetString(ms.ToArray());
}
}
}
[ DllImport ( "kernel32" ) ]
private static extern bool WritePrivateProfileString ( string section ,string key , string val , string filePath ) ;
//读ini文件(字符
[ DllImport ( "kernel32" ) ]
private static extern int GetPrivateProfileString ( string section ,string key , string def , StringBuilder retVal ,int size , string filePath ) ; //读ini文件(数字
[ DllImport ( "kernel32" ) ]
private static extern int GetPrivateProfileInt 的( string section ,string key , int def , string filePath ) ; //////////////////////////////////////////////////////////////
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text; namespace EchonComponentLibrary
{
/// <summary>
/// IniFile 的摘要说明。
/// </summary>
public class IniFile
{
private string FFileName; [DllImport("kernel32")]
private static extern int GetPrivateProfileInt(
string lpAppName,
string lpKeyName,
int nDefault,
string lpFileName
);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName
); public IniFile(string filename)
{
FFileName = filename;
}
public int ReadInt(string section,string key,int def)
{
return GetPrivateProfileInt(section,key,def,FFileName);
}
public string ReadString(string section,string key,string def)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section,key,def,temp,1024,FFileName);
return temp.ToString();
}
public void WriteInt(string section,string key,int iVal)
{
WritePrivateProfileString(section,key,iVal.ToString(),FFileName);
}
public void WriteString(string section,string key,string strVal)
{
WritePrivateProfileString(section,key,strVal,FFileName);
}
public void DelKey(string section,string key)
{
WritePrivateProfileString(section,key,null,FFileName);
}
public void DelSection(string section)
{
WritePrivateProfileString(section,null,null,FFileName);
} }
}