最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#程序啟動(dòng)項(xiàng)的設(shè)置方法

 更新時(shí)間:2018年11月16日 12:53:22   作者:唐宋元明清2188  
這篇文章主要為大家詳細(xì)介紹了C#程序啟動(dòng)項(xiàng)的設(shè)置方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了C#程序啟動(dòng)項(xiàng)的設(shè)置方法,供大家參考,具體內(nèi)容如下

托盤(pán)圖標(biāo)設(shè)置

新建一個(gè)NotifyIcon,會(huì)在托盤(pán)處顯示一個(gè)圖標(biāo)。

NotifyIcon.Icon可以直接設(shè)置一個(gè)ico圖片,也可以延用原有程序的圖標(biāo)。

notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);

public partial class MainWindow : Window
 {
  private NotifyIcon notifyIcon;

  public MainWindow()
  {
   InitializeComponent();
   SetNotifyIcon();
   this.Hide();
  }

  #region NotifyIcon

  private void SetNotifyIcon()
  {
   this.notifyIcon = new NotifyIcon();
   this.notifyIcon.BalloonTipText = "磁盤(pán)清理工具";
   this.notifyIcon.ShowBalloonTip(2000);
   this.notifyIcon.Text = "磁盤(pán)清理工具:每20天清理一次";
   this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
   this.notifyIcon.Visible = true;
   //打開(kāi)菜單項(xiàng)
   MenuItem open = new MenuItem("打開(kāi)");
   open.Click += new EventHandler(Show);
   //退出菜單項(xiàng)
   MenuItem exit = new MenuItem("退出");
   exit.Click += new EventHandler(Close);
   //關(guān)聯(lián)托盤(pán)控件
   MenuItem[] childen = new MenuItem[] { open, exit };
   notifyIcon.ContextMenu = new ContextMenu(childen);

   this.notifyIcon.MouseDoubleClick += new MouseEventHandler((o, e) =>
   {
    if (e.Button == MouseButtons.Left) this.Show(o, e);
   });
  }

  private void Show(object sender, EventArgs e)
  {
   this.Visibility = Visibility.Visible;
   this.ShowInTaskbar = true;
   this.Activate();
  }

  private void Hide(object sender, EventArgs e)
  {
   this.ShowInTaskbar = false;
   this.Visibility = Visibility.Hidden;
  }

  private void Close(object sender, EventArgs e)
  {
   System.Windows.Application.Current.Shutdown();
  }

  #endregion

  #region 窗口

  private void MinimizeButton_OnClick(object sender, RoutedEventArgs e)
  {
   WindowState = WindowState.Minimized;
  }

  private void CloseButton_OnClick(object sender, RoutedEventArgs e)
  {
   this.Hide();
  }

  private void HeaderGrid_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
   if (e.ButtonState == MouseButtonState.Pressed)
   {
    this.DragMove();
   }
  }

  #endregion
 }

禁用多進(jìn)程啟動(dòng)

//禁止雙進(jìn)程
 bool canCreateNew;
 using (System.Threading.Mutex m = new System.Threading.Mutex(true, System.Windows.Forms.Application.ProductName, out canCreateNew))
 {
  if (!canCreateNew)
  {
   this.Shutdown();
  }
 }

刪除原有進(jìn)程

/// <summary>
 /// 刪除原有進(jìn)程
 /// </summary>
 /// <param name="processName"></param>
 private void KillProcess(string processName)
 {
  //得到所有打開(kāi)的進(jìn)程 
  try
  {
   Process currentProcess = Process.GetCurrentProcess();
   var processes = Process.GetProcessesByName(processName).Where(process=> process.Id!=currentProcess.Id);
   foreach (Process thisproc in processes)
   {
    //找到程序進(jìn)程,kill之。
    if (!thisproc.CloseMainWindow())
    {
     thisproc.Kill();
    }
   }
  }
  catch (Exception ex)
  {
    
  }
 }

設(shè)置開(kāi)機(jī)自啟動(dòng)

private void SetAppAutoRun(bool autoRun)
 {
  if (autoRun) //設(shè)置開(kāi)機(jī)自啟動(dòng) 
  {
   string path = System.Windows.Forms.Application.ExecutablePath;
   RegistryKey rk = Registry.LocalMachine;
   RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
   rk2.SetValue("JcShutdown", path);
   rk2.Close();
   rk.Close();
  }
  else //取消開(kāi)機(jī)自啟動(dòng) 
  {
   RegistryKey rk = Registry.LocalMachine;
   RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
   rk2.DeleteValue("JcShutdown", false);
   rk2.Close();
   rk.Close();
  }
 }

App.cs中完整代碼:

public partial class App : Application
 {
  public App()
  {
   //禁止雙進(jìn)程
   bool canCreateNew;
   using (System.Threading.Mutex m = new System.Threading.Mutex(true, System.Windows.Forms.Application.ProductName, out canCreateNew))
   {
    if (!canCreateNew)
    {
     this.Shutdown();
    }
   }

   SetAppAutoRun(true);

   Startup += App_Startup;
  }

  private void SetAppAutoRun(bool autoRun)
  {
   if (autoRun) //設(shè)置開(kāi)機(jī)自啟動(dòng) 
   {
    MessageBox.Show("設(shè)置開(kāi)機(jī)自啟動(dòng),需要修改注冊(cè)表", "提示"); // hovertree.com
    string path = System.Windows.Forms.Application.ExecutablePath;
    RegistryKey rk = Registry.LocalMachine;
    RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
    rk2.SetValue("JcShutdown", path);
    rk2.Close();
    rk.Close();
   }
   else //取消開(kāi)機(jī)自啟動(dòng) 
   {
    MessageBox.Show("取消開(kāi)機(jī)自啟動(dòng),需要修改注冊(cè)表", "提示");
    RegistryKey rk = Registry.LocalMachine;
    RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
    rk2.DeleteValue("JcShutdown", false);
    rk2.Close();
    rk.Close();
   }
  }

  private void App_Startup(object sender, StartupEventArgs e)
  {
   new AutoCleanCacheHelper(CleanCacheVeiwModel.ViewModel).Start();
  }
 }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 一起來(lái)學(xué)習(xí)C#的觀察者模式

    一起來(lái)學(xué)習(xí)C#的觀察者模式

    這篇文章主要為大家詳細(xì)介紹了C#的觀察者模式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-03-03
  • C#讀取csv格式文件的方法

    C#讀取csv格式文件的方法

    這篇文章主要介紹了C#讀取csv格式文件的方法,包括針對(duì)csv文件操作的規(guī)則,實(shí)例代碼部分包含了數(shù)據(jù)有效性驗(yàn)證及行列驗(yàn)證等內(nèi)容,邏輯嚴(yán)謹(jǐn),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2014-10-10
  • ActiveMQ在C#中的應(yīng)用示例分析

    ActiveMQ在C#中的應(yīng)用示例分析

    這篇文章主要介紹了ActiveMQ在C#中的應(yīng)用,簡(jiǎn)單介紹了ActiveMQ的功能、下載及在C#中的具體使用方法,需要的朋友可以參考下
    2016-07-07
  • C#中如何限制TextBox控件內(nèi)輸入值的范圍

    C#中如何限制TextBox控件內(nèi)輸入值的范圍

    這篇文章主要介紹了C#中如何限制TextBox控件內(nèi)輸入值的范圍,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • 淺拷貝和深拷貝深入理解(shallow copy VS deep copy)

    淺拷貝和深拷貝深入理解(shallow copy VS deep copy)

    淺拷貝和深拷貝深入理解(shallow copy VS deep copy) 本文重點(diǎn)討論引用類(lèi)型變量的拷貝機(jī)制和實(shí)現(xiàn)
    2014-01-01
  • C#圖表開(kāi)發(fā)之Chart詳解

    C#圖表開(kāi)發(fā)之Chart詳解

    C#中的Chart控件用于開(kāi)發(fā)圖表功能,具有Series和ChartArea兩個(gè)重要屬性,Series屬性是SeriesCollection類(lèi)型,包含多個(gè)Series對(duì)象,每個(gè)Series代表圖表中的一個(gè)數(shù)據(jù)系列,Series對(duì)象有一個(gè)Points屬性,用于存儲(chǔ)數(shù)據(jù)點(diǎn),每個(gè)數(shù)據(jù)點(diǎn)是一個(gè)DataPoint對(duì)象
    2024-12-12
  • ItemsControl 數(shù)據(jù)綁定的兩種方式

    ItemsControl 數(shù)據(jù)綁定的兩種方式

    這篇文章主要介紹了ItemsControl 數(shù)據(jù)綁定的兩種方式,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03
  • c# 異步編程基礎(chǔ)講解

    c# 異步編程基礎(chǔ)講解

    這篇文章主要介紹了c# 異步編程的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-04-04
  • C#將字母或數(shù)字加密成字母的方法

    C#將字母或數(shù)字加密成字母的方法

    這篇文章主要介紹了C#將字母或數(shù)字加密成字母的方法,涉及C#操作字符串的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • c#如何實(shí)現(xiàn)接口事件

    c#如何實(shí)現(xiàn)接口事件

    這篇文章主要介紹了c#如何實(shí)現(xiàn)接口事件,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下
    2020-10-10

最新評(píng)論

康马县| 宁国市| 枝江市| 广宁县| 南昌县| 方城县| 图们市| 营口市| 双柏县| 奉贤区| 抚松县| 会同县| 姜堰市| 永平县| 衡南县| 陈巴尔虎旗| 博罗县| 阿尔山市| 蛟河市| 江孜县| 磐安县| 昭苏县| 潢川县| 兰州市| 维西| 石城县| 墨江| 桦甸市| 汉寿县| 黔西县| 紫阳县| 伽师县| 镇原县| 克拉玛依市| 大丰市| 新余市| 江都市| 乌审旗| 遵化市| 巴彦县| 顺平县|