日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#实现winform软件开机自动启动并最小化到系统托盘

發布時間:2024/4/17 C# 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#实现winform软件开机自动启动并最小化到系统托盘 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、開機自動啟動:

拖一個CheckBox

1、軟件啟動時給CheckBox重置狀態:

RegistryKey R_local = Registry.LocalMachine;
??????????? RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
??????????? if (R_run.GetValue("BirthdayTipF") == null)
??????????? {
??????????????? checkBox1.Checked = false;
??????????? }
??????????? else
??????????? {
??????????????? checkBox1.Checked = true;
??????????? }
??????????? R_run.Close();
??????????? R_local.Close();

2、CheckChanged事件:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
??????? {
??????????? string R_startPath = Application.ExecutablePath;
??????????? if (checkBox1.Checked == true)
??????????? {
??????????????? RegistryKey R_local = Registry.LocalMachine;
??????????????? RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
??????????????? R_run.SetValue("BirthdayTipF", R_startPath);
??????????????? R_run.Close();
??????????????? R_local.Close();
??????????? }
??????????? else
??????????? {
??????????????? try
??????????????? {
??????????????????? RegistryKey R_local = Registry.LocalMachine;
??????????????????? RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
??????????????????? R_run.DeleteValue("BirthdayTipF", false);
??????????????????? R_run.Close();
??????????????????? R_local.Close();
??????????????? }
??????????????? catch (Exception ex)
??????????????? {
??????????????????? MessageBox.Show("您需要管理員權限修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
??????????????????? throw;
??????????????? }
???????????????
??????????? }
??????? }

二、最小化到系統托盤

1.在form中添加一個NotifyIcon控件     

  2.把87.ico這個圖標放在binDebug目錄下   

using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Text;  
using System.Windows.Forms;  
 
namespace 將程序最小化到系統托盤  
{  
    public partial class Form1 : Form  
    {  
        public Form1()  
        {  
            InitializeComponent();  
        }  
 
        private void Form1_Load(object sender, EventArgs e)  
        {  
            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);  
            notifyIcon1.Icon = new Icon("87.ico");//指定一個圖標     
            notifyIcon1.Visible = false;  
            notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);  
            this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);     
      
 
        }  
 
        private void Form1_SizeChanged(object sender, EventArgs e)  
        {  
            if (this.WindowState == FormWindowState.Minimized)//最小化     
            {  
                this.ShowInTaskbar = false;  
                this.notifyIcon1.Visible = true;  
            }     
 
        }  
 
              private void notifyIcon1_Click(object sender, EventArgs e)  
        {  
            if (this.WindowState == FormWindowState.Minimized)  
                this.WindowState = FormWindowState.Normal;  
            this.Activate();  
            this.notifyIcon1.Visible = false;  
            this.ShowInTaskbar = true;     
 
        }  
 
    }  
} 

轉載于:https://www.cnblogs.com/GT_Andy/archive/2010/03/16/1921836.html

總結

以上是生活随笔為你收集整理的C#实现winform软件开机自动启动并最小化到系统托盘的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。