1.将软件添加到系统自动启动程序,即写注册表项"HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run",
C#支持对注册表的编辑,.NET框架在Microsoft.Win32名字空间中提供了两个类来操作注册表:Registry和RegistryKey。这两个类都是密封类不允许被继承。
RegistryKey类中提供了对注册表操作的方法。要注意的是操作注册表必须符合系统权限,否则将会抛出错误。
设置键值的方法原型如下:
public object SetValue(string name,object value);
示例
//软件添加到系统启动项中:
RegistryKey Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Windows/CurrentVersion/Run",true);
string sFilePath = Application.ExecutablePath;
Reg.SetValue("名字",sFilePath);
//删除指定系统启动项:
Reg.DeleteValue("名字");
2.C#WinForm里面怎样点击标题栏的最小化按钮后,实现跟MSN一样的效果
#region 最小化到右下角托盘
private void ThirdShopList_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
normalToMinimized();
}
private void ThirdShopList_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
normalToMinimized();
}
}
private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
minimizedToNormal();
}
}
private void minimizedToNormal()
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
notifyIcon.Visible = false;
}
private void normalToMinimized()
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
this.notifyIcon.Visible = true;
}
#endregion