Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new MyCustomApplicationContext());
- }
- }
- public class MyCustomApplicationContext : ApplicationContext
- {
- private NotifyIcon trayIcon;
- public MyCustomApplicationContext ()
- {
- // Initialize Tray Icon
- trayIcon = new NotifyIcon()
- {
- Icon = Resources.AppIcon,
- ContextMenu = new ContextMenu(new MenuItem[] {
- new MenuItem("Exit", Exit)
- }),
- Visible = true
- };
- }
- void Exit(object sender, EventArgs e)
- {
- // Hide tray icon, otherwise it will remain shown until user mouses over it
- trayIcon.Visible = false;
- Application.Exit();
- }
- }
- public form1_FormClosing(object sender, EventArgs e)
- {
- e.Cancel = true; // Cancelar o fechamento do form
- Hide(); // Ocultar o form
- // use this.WindowState = FormWindowState.Minimized; para minimizar
- notifyIcon.Visible = true; // Mostrar o notify icon
- }
- 1) Acrescentar no form o "notifyIcon";
- 2) Acrescentar código no evento "notifyIcon1_MouseDoubleClick";
- 3) Código:
- if (this.WindowState == FormWindowState.Minimized)
- {
- notifyIcon1.Icon = SystemIcons.Application;
- notifyIcon1.BalloonTipText = "Aplicação minimizada";
- notifyIcon1.ShowBalloonTip(1000);
- }
- else if (this.WindowState == FormWindowState.Normal)
- {
- notifyIcon1.BalloonTipText = "Aplicação maximizada";
- notifyIcon1.ShowBalloonTip(1000);
- }
- 4) Código no botão que minimiza:
- private void button2_Click(object sender, EventArgs e)
- {
- Hide(); // Ocultar o form
- this.WindowState = FormWindowState.Minimized;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement