/// <summary>
 /// Forces recreation of the context menu when it is next opened.
 /// Used for menus that depend on content created elsewhere, like list of variable names
 /// </summary>
 public void InvalidateContextMenuStrip()
 {
     if (ValueSelectorContextMenuStrip != null)
     {
         ValueSelectorContextMenuStrip.Dispose();
     }
     ValueSelectorContextMenuStrip = null;
 }
    /// <summary>
    /// 让应用程序图标显示在托盘中,
    /// </summary>
    private void SetTrayIcon()
    {
        try
        {
            pathIcon = UnityEngine.Application.dataPath + "/Test/Test.ico";
            trayMenu = new ContextMenuStrip(); //添加右击应用图标弹出退出应用的操作选项
            trayMenu.Items.Add("退出", null, (object sender, EventArgs e) =>
            {
                trayIcon.Visible = false;
                trayMenu.Dispose();
                trayIcon.Dispose();
                UnityEngine.Application.Quit();
            });

            trayIcon                  = new NotifyIcon();
            trayIcon.Text             = UnityEngine.Application.productName;
            trayIcon.Icon             = new Icon(pathIcon);
            trayIcon.ContextMenuStrip = trayMenu;
            trayIcon.Visible          = true;
        }
        catch (Exception e)
        {
            string s = "出错了: " + e.ToString();
            File.WriteAllText(LogPath, s);
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            Save_geometry();

            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
                if (contextMenuStrip1 != null)
                {
                    contextMenuStrip1.Dispose();
                }
                if (copyToolStripMenuItem != null)
                {
                    copyToolStripMenuItem.Dispose();
                }
                if (log_output != null)
                {
                    log_output.Dispose();
                }
                if (selectAllToolStripMenuItem != null)
                {
                    selectAllToolStripMenuItem.Dispose();
                }
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 4
0
        ///<summary>
        ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        ///</summary>
        ///<filterpriority>2</filterpriority>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                items.CollectionChanged -= new CollectionChangeEventHandler(OnCollectionChanged);
                menu.ItemClicked        -= new ToolStripItemClickedEventHandler(OnMenuItemClicked);
                menu.VisibleChanged     -= new EventHandler(OnMenuVisibleChanged);

                foreach (FATabStripItem item in items)
                {
                    if (item != null && !item.IsDisposed)
                    {
                        item.Dispose();
                    }
                }

                if (menu != null && !menu.IsDisposed)
                {
                    menu.Dispose();
                }

                if (sf != null)
                {
                    sf.Dispose();
                }
            }

            base.Dispose(disposing);
        }
        public virtual void ShowContextMenu(MouseEventArgs e, Surface surface)
        {
            bool hasMenu = false;

            foreach (DrawableContainer container in this)
            {
                if (container.hasContextMenu)
                {
                    hasMenu = true;
                    break;
                }
            }
            if (hasMenu)
            {
                ContextMenuStrip menu = new ContextMenuStrip();
                AddContextMenuItems(menu, surface);
                if (menu.Items.Count > 0)
                {
                    menu.Show(surface, e.Location);
                    while (true)
                    {
                        if (menu.Visible)
                        {
                            Application.DoEvents();
                            Thread.Sleep(100);
                        }
                        else
                        {
                            menu.Dispose();
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         m_menu.Dispose();
     }
 }
Ejemplo n.º 7
0
 public void Dispose()
 {
     if (_retrieveVirtualItem != null)
     {
         _listView.CacheVirtualItems   -= MyCacheVirtualItems;
         _listView.RetrieveVirtualItem -= MyRetrieveVirtualItem;
     }
     if (_columnClick != null)
     {
         _listView.ColumnClick -= MyColumnClick;
     }
     if (_itemActivate != null)
     {
         _listView.ItemActivate -= MyItemActivate;
     }
     if (_contextMenu != null)
     {
         _contextMenu.Dispose();
     }
     if (_itemSelectionChanged != null)
     {
         _listView.SelectedIndexChanged -= MySelectedIndexChanged;
         _listView.VirtualItemsSelectionRangeChanged -= MyVirtualItemsSelectionRangeChanged;
     }
 }
Ejemplo n.º 8
0
        private void InitTrayIcon()
        {
            ContextMenuStrip context = new ContextMenuStrip();

            context.Items.AddRange(new ToolStripItem[]
            {
                new ToolStripMenuItem("Show log", null, (q, w) => Process.Start(logFile)),
                new ToolStripMenuItem("Clear log", null, (q, w) => File.Delete(logFile)),
                new ToolStripMenuItem("Open app location", null, (q, w) => Process.Start(Path.GetDirectoryName(Application.ExecutablePath))),
                new ToolStripMenuItem("Exit", null, (q, w) => Application.Exit())
            });

            icon = new NotifyIcon()
            {
                Icon             = Properties.Resources.synchronize,
                Text             = AppName,
                ContextMenuStrip = context,
                Visible          = true
            };
            icon.MouseClick += (obj, args) =>
            {
                if (args.Button == MouseButtons.Left)
                {
                    Process.Start(logFile);
                }
            };

            Application.ApplicationExit += (obj, args) =>
            {
                icon.Dispose();
                context.Dispose();
            };
        }
Ejemplo n.º 9
0
        public override void DisposeScreen()
        {
            CancelAsync();

            AnimatedThreadWorker.Dispose();

            if (_itemPrintReportGeneralData != null)
            {
                _itemPrintReportGeneralData.Dispose();
            }
            if (_itemPrintReportTechnicalCondition != null)
            {
                _itemPrintReportTechnicalCondition.Dispose();
            }
            if (_buttonPrintMenuStrip != null)
            {
                _buttonPrintMenuStrip.Dispose();
            }


            if (_preResult != null)
            {
                _preResult.Clear();
                _preResult = null;
            }
            Dispose(true);
        }
        private void RefreshContextMenuStrip()
        {
            // appropriate menu has already been created recently
            if (_lastMenuObject == Tree.SelectedObject && DateTime.Now.Subtract(_lastMenuBuilt) < TimeSpan.FromSeconds(2))
            {
                return;
            }

            //clear the old menu strip first so old shortcuts cannot be activated during
            if (_menu != null)
            {
                _menu.Dispose();
            }

            if (Tree.SelectedObjects.Count <= 1)
            {
                _menu = GetMenuIfExists(_lastMenuObject = Tree.SelectedObject);
            }
            else
            {
                _menu = GetMenuIfExists(_lastMenuObject = Tree.SelectedObjects);
            }

            _lastMenuBuilt = DateTime.Now;
        }
Ejemplo n.º 11
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         items.CollectionChanged -= OnCollectionChanged;
         menu.ItemClicked        -= OnMenuItemClicked;
         menu.VisibleChanged     -= OnMenuVisibleChanged;
         foreach (BrowserTabStripItem item in items)
         {
             if (item != null && !item.IsDisposed)
             {
                 item.Dispose();
             }
         }
         if (menu != null && !menu.IsDisposed)
         {
             menu.Dispose();
         }
         if (sf != null)
         {
             sf.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 12
0
 public void Delete()
 {
     //Globals.UnsucscribeToolStripMenuItem(contextMenuStripPhrases);
     //Globals.UnsucscribeToolStripMenuItem(contextMenuStripOsnastka);
     contextMenuStripPhrases.Dispose();
     contextMenuStripOsnastka.Dispose();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 割り当てられたリソースを解放します。
        /// </summary>
        /// <param name="disposing">マネージドリソースの解放をする場合は true</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                AllowDragMove = false;

                if (OffScreen != null)
                {
                    OffScreen.Dispose();
                    OffScreen = null;
                }

                if (this.Components != null)
                {
                    this.Components.Dispose();
                    this.Components = null;
                }

                if (ContextMenuStrip != null)
                {
                    ContextMenuStrip.Dispose();
                    ContextMenuStrip = null;
                }
            }

            InvokeWithThreadSafe(() => {
                base.Dispose(disposing);
            });
        }
Ejemplo n.º 14
0
 public void Dispose()
 {
     if (notificationMenu != null)
     {
         try
         {
             notificationMenu.Dispose();
         }
         catch
         {
             // Ignore any exception from dispose
         }
     }
     if (notifyIcon != null)
     {
         try
         {
             notifyIcon.Dispose();
         }
         catch
         {
             // Ignore any exception from dispose
         }
     }
 }
Ejemplo n.º 15
0
        private void InitTrayIcon()
        {
            ContextMenuStrip context = new ContextMenuStrip();

            context.Items.AddRange(new ToolStripItem[]
            {
                new ToolStripMenuItem("Exit", null, (q, w) => Application.Exit())
            });

            icon = new NotifyIcon()
            {
                Icon             = Properties.Resources.synchronize,
                Text             = AppName,
                ContextMenuStrip = context,
                Visible          = true
            };

            icon.MouseClick += (obj, args) =>
            {
                //if (args.Button == MouseButtons.Left)
                //	Process.Start();
            };

            Application.ApplicationExit += (obj, args) =>
            {
                if (!process.HasExited)
                {
                    process.Kill();
                }
                icon.Dispose();
                context.Dispose();
            };
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Disposes resources used by the control.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }

                mnuLaunch.Click -= mnuLaunch_Click;
                mnuRename.Click -= mnuRename_Click;
                mnuForget.Click -= mnuForget_Click;
                mnuDelete.Click -= mnuDelete_Click;

                mnuLaunch.Dispose();
                mnuRename.Dispose();
                mnuForget.Dispose();
                mnuDelete.Dispose();

                popMenu.Items.Clear();
                popMenu.Dispose();
                this.ContextMenu = null;
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 17
0
        //コンテキストメニュー表示
        public void ShowContextMenu(IPoderosaMenuGroup[] menus, ICommandTarget target, Point point_screen, ContextMenuFlags flags)
        {
            //まずソート
            ICollection      sorted = PositionDesignationSorter.SortItems(menus);
            ContextMenuStrip cm     = new ContextMenuStrip();

            MenuUtil.BuildContextMenu(cm, new ConvertingEnumerable <IPoderosaMenuGroup>(sorted), target);
            if (cm.Items.Count == 0)
            {
                cm.Dispose();
                return;
            }

            //キーボード操作をトリガにメニューを出すときは、選択があったほうが何かと操作しやすい。
            if ((flags & ContextMenuFlags.SelectFirstItem) != ContextMenuFlags.None)
            {
                cm.Items[0].Select();
            }

            // ContextMenuStrip is not disposed automatically and
            // its instance sits in memory till application end.
            // To release a document object related with some menu items,
            // we need to dispose ContextMenuStrip explicitly soon after it disappeared.
            cm.VisibleChanged += new EventHandler(ContextMenuStripVisibleChanged);

            try {
                cm.Show(this, this.PointToClient(point_screen));
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
            }
        }
Ejemplo n.º 18
0
 public void Dispose()
 {
     _selectionMenu.Dispose();
     _settingsMenu.Dispose();
     NotifyIcon.Dispose();
     _updateMenuItem.Dispose();
 }
Ejemplo n.º 19
0
 // Click "Exit" on ContextMenu
 private static void ExitApplication(object sender, EventArgs e)
 {
     if (Configure != null)
     {
         Configure.Dispose();
     }
     //
     if (About != null)
     {
         About.Dispose();
     }
     //
     if (IrdaComPort.isOpen)
     {
         IrdaComPort.Close();
     }
     //
     tmrProgram.Enabled = false;
     tmrProgram.Dispose();
     //
     IrdaContextMenu.Dispose();
     IrdaNotifyIcon.Dispose();
     //
     Application.Exit();
 }
Ejemplo n.º 20
0
        private ContextMenuStrip?BuildContextMenuStrip()
        {
            var contextMenuStrip = new ContextMenuStrip {
                ImageList = _imageList
            };

            contextMenuStrip.Closed += (o, e) =>
            {
                if (ReferenceEquals(_notifyIcon.ContextMenuStrip, o))
                {
                    _notifyIcon.ContextMenuStrip = null;
                }
            };
            contextMenuStrip.ItemClicked += (o, e) =>
            {
                if (e.ClickedItem.Tag is Action act)
                {
                    act.Invoke();
                }
            };
            var items = BuildMenuItems();

            if (items is null || !items.Any())
            {
                contextMenuStrip.Dispose();
                return(null);
            }

            contextMenuStrip.Items.AddRange(items);
            contextMenuStrip.PerformLayout();
            return(contextMenuStrip);
        }
Ejemplo n.º 21
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    menuItem.Dispose();
                    intLabel.Dispose();
                    intBar.Dispose();
                    intPanel.Dispose();
                    strLabel.Dispose();
                    strBox.Dispose();
                    strPanel.Dispose();
                    multiButtons.Clear();
                    SubMenuButton.Dispose();
                    MenuButton.Dispose();
                    DropDownMenu.Dispose();
                    DropDownSubMenu.Dispose();
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.
                multiButtons    = null;
                MenuButton      = null;
                SubMenuButton   = null;
                DropDownMenu    = null;
                DropDownSubMenu = null;
                disposedValue   = true;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Releases all resources used by the component.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    // Kill the menu strip
                    if (_cms != null)
                    {
                        _cms.Dispose();
                        _cms = null;
                    }

                    // Unhook from events
                    _ribbonTab.DesignTimeAddGroup    -= new EventHandler(OnAddGroup);
                    _ribbonTab.DesignTimeContextMenu -= new MouseEventHandler(OnContextMenu);
                    _changeService.ComponentRemoving -= new ComponentEventHandler(OnComponentRemoving);
                    _changeService.ComponentChanged  -= new ComponentChangedEventHandler(OnComponentChanged);
                }
            }
            finally
            {
                // Must let base class do standard stuff
                base.Dispose(disposing);
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// 释放资源
 /// </summary>
 /// <param name="disposing"></param>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
     }
     if (contextMenuStrip1 != null)
     {
         contextMenuStrip1.Dispose();
         contextMenuStrip1 = null;
     }
     if (toolSave != null)
     {
         toolSave.Dispose();
         toolSave = null;
     }
     if (toolReset != null)
     {
         toolReset.Dispose();
         toolReset = null;
     }
     if (toolStripSeparator1 != null)
     {
         toolStripSeparator1.Dispose();
         toolStripSeparator1 = null;
     }
     if (components != null)
     {
         components.Dispose();
         components = null;
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// This method will show the supplied context menu at the mouse cursor, also makes sure it has focus and it's not visible in the taskbar.
        /// </summary>
        /// <param name="menu"></param>
        private static void ShowMenuAtCursor(ContextMenuStrip menu)
        {
            // find a suitable location
            Point     location      = Cursor.Position;
            Rectangle menuRectangle = new Rectangle(location, menu.Size);

            menuRectangle.Intersect(WindowCapture.GetScreenBounds());
            if (menuRectangle.Height < menu.Height)
            {
                location.Offset(-40, -(menuRectangle.Height - menu.Height));
            }
            else
            {
                location.Offset(-40, -10);
            }
            // This prevents the problem that the context menu shows in the task-bar
            User32.SetForegroundWindow(PluginUtils.Host.NotifyIcon.ContextMenuStrip.Handle);
            menu.Show(location);
            menu.Focus();

            // Wait for the menu to close, so we can dispose it.
            while (true)
            {
                if (menu.Visible)
                {
                    Application.DoEvents();
                    Thread.Sleep(100);
                }
                else
                {
                    menu.Dispose();
                    break;
                }
            }
        }
 // ========================================
 // method
 // ========================================
 public virtual void Dispose()
 {
     if (_contextMenu != null)
     {
         _contextMenu.Dispose();
     }
     GC.SuppressFinalize(this);
 }
Ejemplo n.º 26
0
 void Owner_Disposed(object sender, EventArgs e)
 {
     if (_cms != null)
     {
         _cms.Dispose();
         _cms = null;
     }
 }
Ejemplo n.º 27
0
 public void Dispose()
 {
     _window.Dispose();
     _scrollX.Dispose();
     _scrollY.Dispose();
     _menu.Dispose();
     DisposeTabs();
 }
Ejemplo n.º 28
0
 public static void Destroy()
 {
     if (m_ctx != null)
     {
         m_ctx.Close();
         m_ctx.Dispose();
         m_ctx = null;
     }
 }
Ejemplo n.º 29
0
 void DisposeContextMenu(object sender, EventArgs e)
 {
     Application.Idle -= DisposeContextMenu;
     if (m_contextMenu != null)
     {
         m_contextMenu.Dispose();
         m_contextMenu = null;
     }
 }
Ejemplo n.º 30
0
 void DisposeContextMenu(object sender, EventArgs e)
 {
     Application.Idle -= DisposeContextMenu;
     if (m_contextMenuStrip != null && !m_contextMenuStrip.IsDisposed)
     {
         m_contextMenuStrip.Dispose();
         m_contextMenuStrip = null;
     }
 }