示例#1
0
        public ToolStripItem[] CreateMenuItems()
        {
            menuItemSeparator?.Dispose();
            menuItemSeparator = new ToolStripSeparator();

            menuItemExit?.Dispose();
            menuItemExit = new ToolStripMenuItem("E&xit", null, OnExit);

            return(new ToolStripItem[] {
                menuItemSeparator,
                menuItemExit,
            });
        }
示例#2
0
        public static void RemoveItem(this ToolStripItemCollection menu, string path)
        {
            string[] parts = path.Split('/', '\\');
            ToolStripItemCollection current = menu;

            for (int i = 0; i < parts.Length; i++)
            {
                bool isLast = i == parts.Length - 1;
                if (current.ContainsKey(parts[i]))
                {
                    ToolStripItem item = current[parts[i]];
                    if (isLast)
                    {
                        current.Remove(item);
                        item.Dispose();
                    }

                    if (item is ToolStripDropDownItem mitem)
                    {
                        current = mitem.DropDownItems;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
示例#3
0
 public static void DisposeItem(ToolStripItem item)
 {
     if (item != null && !item.IsDisposed)
     {
         item.Dispose();
     }
 }
示例#4
0
        public void DestroyMenuItem(ToolStripItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            item.Dispose();
        }
示例#5
0
        private void Command_CommandRemoved(object sender, CommandEventArgs e)
        {
            ToolStripItem toolStripItem = this.FindMenuItem(e.Command);

            if (toolStripItem != null)
            {
                base.DropDownItems.Remove(toolStripItem);
                this.servicedComponents.Remove(toolStripItem);
                toolStripItem.Dispose();
            }
        }
示例#6
0
        private void RemoveView(QueueStufferView child, bool dispose)
        {
            var childIndex = _views.IndexOf(child);

            if (childIndex == -1)
            {
                return;
            }

            //remove toolStripItem.
            var           key      = (childIndex + 1).ToString();
            ToolStripItem toolItem = FindButtonByText(key);

            if (toolItem != null)
            {
                toolStrip1.Items.Remove(toolItem);
                toolItem.Click -= activateToolStripButton_Click;
                toolItem.Dispose();
            }

            //shift tooltip keys
            for (int i = childIndex; i < _views.Count; i++)
            {
                var text   = (i + 1).ToString();
                var button = FindButtonByText(text);
                if (button != null)
                {
                    button.Text = i.ToString();
                }
            }

            //drop child view
            _views.RemoveAt(childIndex);
            if (dispose)
            {
                child.Closed    -= view_Closed;
                child.Activated -= view_Activated;

                if (child.Visible)
                {
                    child.Close();
                }
                child.Dispose();
            }


            if (ActiveMdiChild != null)
            {
                var index = _views.IndexOf(ActiveMdiChild as QueueStufferView);
                ActivateToolstripButton((index + 1).ToString());
            }

            startBatchToolStripButton.Enabled = _views.Count > 0;
        }
示例#7
0
        private void listIcons(string folder)
        {
            if (Directory.Exists(folder))
            {
                List <string> exts = new List <string>()
                {
                    ".png", ".bmp", ".jpg", ".ico", ".gif"
                };
                string[] logoFiles = Directory.GetFiles($"{AppPath}icons");
                if (logoFiles.Length == miLogoItems.DropDownItems.Count)
                {
                    return;
                }

                overlayIcons.Clear();
                miLogoItems.DropDownItems.Clear();
                //foreach( ToolStripItem item in iconItems )
                //{
                //    iconItems.Remove( item );
                //    item.Dispose();
                //}
                for (int i = iconItems.Count - 1; i >= 0; i--)
                {
                    ToolStripItem item = iconItems[i];
                    iconItems.Remove(item);
                    item.Dispose();
                }
                iconItems.Clear();

                foreach (string logoFile in logoFiles)
                {
                    string itemText = Path.GetFileName(logoFile);
                    string itemExt  = Path.GetExtension(logoFile);
                    if (exts.Contains(itemExt.ToLower()))
                    {
                        overlayIcons.Add(itemText, logoFile);

                        using (var fs = new FileStream(logoFile, FileMode.Open))
                        {
                            var           img  = new Bitmap(fs, true);
                            ToolStripItem item = miLogoItems.DropDownItems.Add(itemText, (Bitmap)img.Clone());
                            iconItems.Add(item);
                            img.Dispose();
                        }
                    }
                }
            }
        }
        void ICustomize.RemoveCustomizeBaseItem(IBaseItemDB pBaseItem)
        {
            if (pBaseItem == null)
            {
                return;
            }
            //
            ToolStripItem item = pBaseItem as ToolStripItem;

            if (item == null)
            {
                return;
            }
            this.m_CustomizeBaseItems.Remove(item);
            this.DropDownItems.Remove(item);
            item.Dispose();
        }
示例#9
0
 public void Unload()
 {
     m_MenuItem.Visible = false;
     m_MenuItem.Dispose();
     m_MenuItem = null;
     if ((m_Editor != null) && (!m_Editor.Disposing))
     {
         try
         {
             m_Editor.Close();
             m_Editor.Dispose();
         }
         catch
         {
         }
         m_Editor = null;
     }
 }
示例#10
0
            private void RemoveItem(ToolStripItem item)
            {
                int index;

                try
                {
                    index = this._itemList.IndexOf(item);
                    this._itemList.Remove(item);
                }
                finally
                {
                    item.Dispose();
                }
                if (this._itemList.Count > 0)
                {
                    this.listBoxItems.ClearSelected();
                    index = Math.Max(0, Math.Min(index, this.listBoxItems.Items.Count - 1));
                    this.listBoxItems.SelectedIndex = index;
                }
            }
示例#11
0
        private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (searc_box != null)
            {
                doc_headBindingNavigator.Items.Remove(searc_box);
                searc_box.Dispose();
            }
            Type type = ((ComboboxItem)searchComboBox.SelectedItem).itemType;

            if (type == null)
            {
                doc_headBindingSource.Filter = "";
                searc_box = null;
                return;
            }
            else if (type == typeof(DataGridViewTextBoxColumn))
            {
                ToolStripTextBox tb = new ToolStripTextBox();
                tb.BorderStyle  = BorderStyle.Fixed3D;
                tb.TextChanged += new EventHandler(tb_TextChanged);
                searc_box       = tb;
            }
            else if (type == typeof(DataGridViewCheckBoxColumn))
            {
                CheckBoxToolStripItem cb = new CheckBoxToolStripItem();
                cb.OnChecked += new EventHandler(cb_OnChecked);
                searc_box     = cb;
            }
            else if (type == typeof(DataGridViewComboBoxColumn))
            {
                ToolStripComboBox cb = new ToolStripComboBox("search_box");
                cb.FlatStyle = FlatStyle.System;
                foreach (DataRowView row in ((ComboboxItem)searchComboBox.SelectedItem).bindingSource as BindingSource)
                {
                    cb.Items.Add(new ComboboxItem(row["value"].ToString(), row["id"]));
                }
                cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
                searc_box = cb;
            }
            doc_headBindingNavigator.Items.Add(searc_box);
        }
示例#12
0
        public static void ClearAndDispose(this ToolStripItemCollection items,
                                           int startIndex, int endIndex)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }
            if (startIndex < 0 || startIndex > items.Count)
            {
                throw new ArgumentOutOfRangeException("startIndex");
            }
            if (endIndex < startIndex || endIndex > items.Count)
            {
                throw new ArgumentOutOfRangeException("endIndex");
            }

            for (int i = endIndex - 1; i >= startIndex; i--)
            {
                ToolStripItem item = items[i];
                items.RemoveAt(i);
                item.Dispose();
            }
        }
        // 印刷ボタンの付け替え / ページ設定ボタン追加
        private void buttonsCustomize()
        {
            ToolStrip tools = (ToolStrip)Controls[@"toolStrip1"];

            if (toolStripButtonPrint_ == null)
            {
                ToolStripItem oldItem = (ToolStripItem)tools.Items[0];
                toolStripButtonPrint_ = new ToolStripButton(oldItem.Text, (Image)oldItem.Image.Clone(),
                                                            new EventHandler(SettingPrintPreviewDialog_toolStripButtonPrintClick));
                toolStripButtonPrint_.DisplayStyle = oldItem.DisplayStyle;
                tools.Items.Insert(0, toolStripButtonPrint_);
                tools.Items.Remove(oldItem);
                oldItem.Dispose();
            }

            if (toolStripButtonPageSetup_ == null)
            {
                toolStripButtonPageSetup_ = new ToolStripButton(@"ページ設定", imageList_.Images[0],
                                                                new EventHandler(SettingPrintPreviewDialog_toolStripButtonPageSetupClick));
                toolStripButtonPageSetup_.ImageTransparentColor = imageList_.TransparentColor;
                toolStripButtonPageSetup_.DisplayStyle          = ToolStripItemDisplayStyle.Image;
                tools.Items.Insert(0, toolStripButtonPageSetup_);
            }
        }
示例#14
0
        private void DisposeDropDownItem(ToolStripItem item)
        {
            // PROBLEM:
            // Because we are using the MouseUp event from the menu items,
            // and also removing/disposing those items as a result of that event,
            // the top level drop down button UI tends to hang and cause strange
            // behaviour. The problem is particularly apparent after the last
            // menu item has been removed. Small rectangles left in the cornor
            // of the screen, and forms spontaneously popping infront of the
            // active form are two of the most annoying problems.
            //
            // REASON (maybe):
            // After much digging and testing, I've managed to narrow it down
            // to stuck/corrupt mouse event messages. These screwed up messages
            // tend to fire on other controls and cause unintended UI changes.
            // My best guess is that the item is disposed before the WM_LBUTTONUP
            // is actually received and processed by the menu control.
            //
            // I tried to find a decent logical way around it, found the following
            // to work the best.
            //
            // WORKAROUND:
            // We selectively call the PerfomClick method on menu items just
            // before they are removed and disposed. This seems to clear out
            // any remaining mouse button messages and allows the items to go
            // away cleanly and quietly. The only reason we don't call it on
            // every disposal is because it causes the top level menu to close,
            // and this is not desirable if users want to manage multiple items
            // without having to reopen the menu after every click.

            // If the item is not visible, always perform a click.
            if (!item.Visible)
            {
                item.PerformClick();
            }
            else
            {
                // If the item is the last item in a menu containing a fixed parent item, perform a click.
                // (Parent item + Separator + last item = 3)
                if (dropDownControl.DropDownItems.Count == 3 && hasParentMenu)
                {
                    item.PerformClick();
                }
                // If the item is the last item, regardless of a fixed parent item, perform a click.
                else if (dropDownControl.DropDownItems.Count == 1)
                {
                    item.PerformClick();
                }
            }

            // Do the usual clean up and disposal stuff.
            if (dropDownControl.DropDownItems.Count < 1)
            {
                dropDownControl.DropDownItems.Clear();
            }
            else
            {
                item.Visible = false;
                dropDownControl.DropDownItems.Remove(item);
            }

            item.MouseUp -= ItemClicked;
            item.Dispose();
        }
示例#15
0
 public void Unload()
 {
     m_MenuItem.Visible = false;
     m_MenuItem.Dispose();
     m_MenuItem = null;
 }