ExplorerRestarter.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using BulePointLilac.Controls;
  2. using BulePointLilac.Methods;
  3. using System;
  4. using System.Diagnostics;
  5. using System.Windows.Forms;
  6. namespace ContextMenuManager.Controls
  7. {
  8. public sealed class ExplorerRestarter : MyListItem
  9. {
  10. public ExplorerRestarter()
  11. {
  12. this.Visible = false;
  13. this.Dock = DockStyle.Bottom;
  14. this.Image = AppImage.Explorer;
  15. this.Text = AppString.Text_RestartExplorer;
  16. MyToolTip.SetToolTip(BtnRestart, AppString.Tip_RestartExplorer);
  17. this.AddCtr(BtnRestart);
  18. this.CanMoveForm();
  19. BtnRestart.MouseDown += (sender, e) => { Explorer.ReStart(); this.Visible = false; };
  20. RestartHandler += (sender, e) => this.Visible = NeedRestart;
  21. }
  22. protected override void OnVisibleChanged(EventArgs e)
  23. {
  24. base.OnVisibleChanged(e);
  25. if(this.Parent != null) this.Parent.Height += Visible ? Height : -Height;
  26. }
  27. private readonly PictureButton BtnRestart = new PictureButton(AppImage.Refresh);
  28. private static event EventHandler RestartHandler;
  29. private static bool needRestart;
  30. public static bool NeedRestart
  31. {
  32. get => needRestart;
  33. set
  34. {
  35. needRestart = value;
  36. RestartHandler?.Invoke(null, null);
  37. }
  38. }
  39. }
  40. public static class Explorer
  41. {
  42. /// <summary>重启Explorer</summary>
  43. public static void ReStart()
  44. {
  45. new Process
  46. {
  47. StartInfo = new ProcessStartInfo
  48. {
  49. FileName = "cmd.exe",
  50. Arguments = "/s /c tskill explorer",
  51. WindowStyle = ProcessWindowStyle.Hidden,
  52. UseShellExecute = true
  53. }
  54. }.Start();
  55. }
  56. }
  57. }