Beispiel #1
0
        /// <summary>
        /// Assigns the context menu to a control.
        /// </summary>
        /// <param name="control">Control to assign the context menu to.</param>
        /// <param name="value">Instance of PopupItem derived class usually ButtonItem to act as context menu for a control. The SubItems collection of the item specified here actually defines the visible context menu items.</param>
        public void SetContextMenuEx(Control control, BaseItem value)
        {
            if (control is DevComponents.DotNetBar.Controls.RichTextBoxEx)
                control = ((DevComponents.DotNetBar.Controls.RichTextBoxEx)control).RichTextBox;
            if (value == null)
            {
                if (m_ContextExMenus.Contains(control))
                {
                    if (m_ContextExHandlers.Contains(control))
                    {
                        ContextMessageHandler h = m_ContextExHandlers[control] as ContextMessageHandler;
                        if (h != null)
                        {
                            h.ContextMenu -= new WmContextEventHandler(this.OnContextMenu);
                            h.ReleaseHandle();
                            h = null;
                        }
                        m_ContextExHandlers.Remove(control);
                    }

                    m_ContextExMenus.Remove(control);
                    control.MouseUp -= new MouseEventHandler(this.ContextExMouseUp);
                    try
                    {
                        control.HandleDestroyed -= new EventHandler(this.ContextExHandleDestroy);
                    }
                    catch { }
                    try
                    {
                        control.HandleCreated -= new EventHandler(this.ContextExHandleCreate);
                    }
                    catch { }
                    try { control.MouseUp -= new MouseEventHandler(this.ContextExMouseUp); }
                    catch { }
                }
            }
            else
            {
                if (m_ContextExMenus.Contains(control))
                {
                    m_ContextExMenus[control] = value;
                }
                else
                {
                    m_ContextExMenus[control] = value;
                    if (!m_ContextExHandlers.Contains(control) && !this.DesignMode)
                    {
                        if (!(control is System.Windows.Forms.TreeView) && !(control is System.Windows.Forms.Form) && 
                            !(control is System.Windows.Forms.Panel
#if FRAMEWORK20
                            || control is System.Windows.Forms.DataGridView
#endif
                            ) && 
                            m_ContextMenuSubclass)
                        {
                            if (control.IsHandleCreated)
                            {
                                ContextMessageHandler h = new ContextMessageHandler();
                                h.ContextMenu += new WmContextEventHandler(this.OnContextMenu);
                                h.ParentControl = control;
                                h.AssignHandle(control.Handle);
                                m_ContextExHandlers[control] = h;
                            }
                            control.HandleDestroyed += new EventHandler(this.ContextExHandleDestroy);
                            control.HandleCreated += new EventHandler(this.ContextExHandleCreate);
                        }
                        if (control is ComboBox)
                        {
                            ComboBox cbo = control as ComboBox;
                            cbo.ContextMenu = new ContextMenu();
                        }
                    }
                    try { control.MouseUp += new MouseEventHandler(this.ContextExMouseUp); }
                    catch { }
                }
            }
        }
Beispiel #2
0
        private void ContextExHandleCreate(object sender, EventArgs e)
        {
            Control control = sender as Control;
            if (control == null)
                return;
            if (m_ContextExHandlers.Contains(control))
                return;

            ContextMessageHandler h = new ContextMessageHandler();
            h.ContextMenu += new WmContextEventHandler(this.OnContextMenu);
            h.ParentControl = control;
            h.AssignHandle(control.Handle);
            m_ContextExHandlers[control] = h;
        }