1.程序中启动其他进程
string path = Application.StartupPath + "\\**.exe";
Process.Start(path);
2.事件触发
private void ButtonClick(object sender, RoutedEventArgs e)
{
Button cmd = (Button)e.OriginalSource;
Type type = this.GetType();
Assembly assembly = type.Assembly;
Window win = (Window)assembly.CreateInstance(
type.Namespace + "." + cmd.Content);
win.ShowDialog();
}
3.ini配置文件读写类
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace Ini
{
public class IniFile
{
public string path;
[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 INIPath)
{
path = INIPath;
}
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
return temp.ToString();
}
}
}
4.CRC校验(多项式A001)http://download.csdn.net/detail/wohaorende/3597075
public string GetCRC(string DATA)
{
long functionReturnValue = 0;
long i = 0;
long J = 0;
byte[] v = null;
v = Encoding.ASCII.GetBytes(DATA);
long CRC = 0;
CRC = 0xffffL;
for (i = 0; i <= (v).Length - 1; i++)
{
CRC = (CRC / 256) * 256L + (CRC % 256L) ^ v[i];
for (J = 0; J <= 7; J++)
{
long d0 = 0;
d0 = CRC & 1L;
CRC = CRC / 2;
if (d0 == 1)
CRC = CRC ^ 0xa001L;
}
}
CRC = CRC % 65536;
functionReturnValue = CRC;
return string.Format("{0:X}", functionReturnValue);
}