Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. static class Program
  2. {
  3. /// <summary>
  4. /// The main entry point for the application.
  5. /// </summary>
  6. [STAThread]
  7. static void Main()
  8. {
  9. Application.EnableVisualStyles();
  10. Application.SetCompatibleTextRenderingDefault(false);
  11.  
  12. Application.Run(new MyCustomApplicationContext());
  13. }
  14. }
  15.  
  16.  
  17. public class MyCustomApplicationContext : ApplicationContext
  18. {
  19. private NotifyIcon trayIcon;
  20.  
  21. public MyCustomApplicationContext ()
  22. {
  23. // Initialize Tray Icon
  24. trayIcon = new NotifyIcon()
  25. {
  26. Icon = Resources.AppIcon,
  27. ContextMenu = new ContextMenu(new MenuItem[] {
  28. new MenuItem("Exit", Exit)
  29. }),
  30. Visible = true
  31. };
  32. }
  33.  
  34. void Exit(object sender, EventArgs e)
  35. {
  36. // Hide tray icon, otherwise it will remain shown until user mouses over it
  37. trayIcon.Visible = false;
  38.  
  39. Application.Exit();
  40. }
  41. }
  42.  
  43. public form1_FormClosing(object sender, EventArgs e)
  44. {
  45. e.Cancel = true; // Cancelar o fechamento do form
  46. Hide(); // Ocultar o form
  47. // use this.WindowState = FormWindowState.Minimized; para minimizar
  48. notifyIcon.Visible = true; // Mostrar o notify icon
  49. }
  50.  
  51. 1) Acrescentar no form o "notifyIcon";
  52. 2) Acrescentar código no evento "notifyIcon1_MouseDoubleClick";
  53. 3) Código:
  54. if (this.WindowState == FormWindowState.Minimized)
  55. {
  56. notifyIcon1.Icon = SystemIcons.Application;
  57. notifyIcon1.BalloonTipText = "Aplicação minimizada";
  58. notifyIcon1.ShowBalloonTip(1000);
  59. }
  60.  
  61. else if (this.WindowState == FormWindowState.Normal)
  62. {
  63. notifyIcon1.BalloonTipText = "Aplicação maximizada";
  64. notifyIcon1.ShowBalloonTip(1000);
  65. }
  66.  
  67. 4) Código no botão que minimiza:
  68. private void button2_Click(object sender, EventArgs e)
  69. {
  70. Hide(); // Ocultar o form
  71. this.WindowState = FormWindowState.Minimized;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement