示例#1
0
        /// <summary>
        /// Displays the icon in the system tray.
        /// </summary>
        public void Display(CheckAndTransmit checkAndTransmit)
        {
            // Put the icon in the system tray and allow it react to mouse clicks.
            ni.MouseClick += new MouseEventHandler(ni_MouseClick);
            ni.Icon        = Resources.MCargaModBus;
            ni.Text        = "Serviço de Comunicação MCarga -> ModBus";
            ni.Visible     = true;

            // Attach a context menu.
            ni.ContextMenuStrip = new ContextMenus().Create(checkAndTransmit);
        }
示例#2
0
        static void Main()
        {
            Assembly assembly  = Assembly.GetExecutingAssembly();
            var      attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
            var      appGuid   = attribute.Value;

            using (Mutex mutex = new Mutex(false, "Global\\" + appGuid))
            {
                bool interfaceStarted = false;
                // Show the system tray icon.
                using (ProcessIcon pi = new ProcessIcon())
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);


                    if (!mutex.WaitOne(0, false))
                    {
                        MessageBox.Show("Programa já em execução!");
                        return;
                    }

                    CheckAndTransmit checkAndTransmit = null;
                    try
                    {
                        checkAndTransmit             = new CheckAndTransmit();
                        checkAndTransmit.ProcessIcon = pi;
                        pi.Display(checkAndTransmit);
                        pi.ChangeIcon((int)ProcessIcon.ICONS.Red);
                        checkAndTransmit.iniciarThreadConexao();
                        // Make sure the application runs!
                        Application.Run();
                    }
                    catch (Exception ex)
                    {
                        checkAndTransmit.LOGGER.Fatal("************* Não foi possível iniciar o processo *************");
                        checkAndTransmit.LOGGER.Fatal(ex.Message);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns>ContextMenuStrip</returns>
        public ContextMenuStrip Create(CheckAndTransmit CaT)
        {
            // Add the default menu options.
            ContextMenuStrip   menu = new ContextMenuStrip();
            ToolStripMenuItem  item;
            ToolStripSeparator sep;

            checkAndTransmit = CaT;
            // Windows Explorer.

            /*
             *          item = new ToolStripMenuItem();
             *          item.Text = "Explorer";
             *          item.Click += new EventHandler(Explorer_Click);
             *          item.Image = Resources.Explorer;
             *          menu.Items.Add(item);
             */

            // About.
            item        = new ToolStripMenuItem();
            item.Text   = "Sobre";
            item.Click += new EventHandler(About_Click);
            item.Image  = Resources.About;
            menu.Items.Add(item);

            // Separator.
            sep = new ToolStripSeparator();
            menu.Items.Add(sep);

            // Exit.
            item        = new ToolStripMenuItem();
            item.Text   = "Sair";
            item.Click += new System.EventHandler(Exit_Click);
            item.Image  = Resources.Exit;
            menu.Items.Add(item);

            return(menu);
        }