Beispiel #1
0
 void tabControlAdv1_SelectedIndexChanging(object sender, SelectedIndexChangingEventArgs args)
 {
     if (args.NewSelectedIndex == 1)
     {
         this.BannerTile.TurnLiveTileOn = true;
         this.EnableTransition.Text     = "Disable Transition";
     }
     else
     {
         this.BannerTile.TurnLiveTileOn = false;
         this.EnableTransition.Text     = "Enable Transition";
     }
 }
Beispiel #2
0
 private void TabControlAdv3_SelectedIndexChanging(object sender, SelectedIndexChangingEventArgs args)
 {
     this.tabControlAdv3.ShowTabCloseButton = false;
     this.tabControlAdv3.RightToLeft        = RightToLeft.No;
     if ((sender as TabControlAdv).TabPages[args.NewSelectedIndex].Text == "Tab Close Button")
     {
         this.tabControlAdv3.ShowTabCloseButton = true;
     }
     else if (args.NewSelectedIndex == 2)
     {
         this.tabControlAdv3.RightToLeft = RightToLeft.Yes;
     }
 }
Beispiel #3
0
 protected virtual void OnSelectedIndexChanging(SelectedIndexChangingEventArgs e)
 {
     this.SelectedIndexChanging?.Invoke(this, e);
     if (!e.Cancel)
     {
         if (this._controlList != null && this._controlList.Count > 0)
         {
             if (!DesignMode && this._ready)
             {
                 if (this.tqb != null)
                 {
                     this.tqb.Dispose();
                 }
                 this.destinationTab         = this._controlList[e.IndexAfter];
                 this.destinationTab.Visible = false;
                 Point loc = this.destinationTab.Location;
                 this.tqb            = new Leayal.Drawing.QuickBitmap(this.destinationTab.Size);
                 this.DrawBackground = false;
                 this.tqb.Graphics.Clear(Color.Transparent);
                 this.tqb.Graphics.CompositingQuality = CompositingQuality.HighQuality;
                 this.tqb.Graphics.InterpolationMode  = InterpolationMode.High;
                 this.tqb.Graphics.SmoothingMode      = SmoothingMode.AntiAlias;
                 this.tqb.Graphics.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                 this.destinationTab.Location         = new Point(this.destinationTab.Size.Width * -2, this.destinationTab.Size.Height * -2);
                 this.destinationTab.Visible          = true;
                 //this.RecursiveInvokePaint(this.tqb.Graphics, this.destinationTab, false);
                 this.destinationTab.DrawToBitmap(tqb.Bitmap, this.destinationTab.ClientRectangle);
                 this.destinationTab.Visible  = false;
                 this.destinationTab.Location = loc;//*/
                 this.countup = 0;
                 if (this.SelectedTab != null)
                 {
                     this.SelectedTab.Visible = false;
                 }
                 this.myTimer.Start();
             }
             else
             {
                 if (this.SelectedTab != null)
                 {
                     this.SelectedTab.Visible = false;
                 }
                 this._controlList[e.IndexAfter].Visible = true;
             }
         }
     }
 }
        private void SelectNextAvailableTabPage()
        {
            if (TabCount <= 1)
                return;

            using (var e = new SelectedIndexChangingEventArgs((TabPageEx)SelectedTab, 0))
            {
                // Fire a Notification Event.
                OnSelectedIndexChanging(e);

                if (!e.Cancel) return;
                for (var i = 1; OnNavigateTabPage(i, false) && i < TabCount; i++)
                {
                }
            }
        }
        protected override void WndProc(ref Message m)
        {
            #region Tab Control Notification Messages

            //if (m.Msg == (int)(User32.Msgs.WM_REFLECT | User32.Msgs.WM_NOTIFY))
            //{
            //    if (!DesignMode)
            //    {
            //        User32.NMTCKEYDOWN tcn = (User32.NMTCKEYDOWN)(System.Runtime.InteropServices.Marshal.PtrToStructure(m.LParam, typeof(User32.NMTCKEYDOWN)));
            //        switch (tcn.hdr.code)
            //        {
            //            // TCN_FIRST, handle virtual keys from tcn.wVKey parameters.
            //            case -550:
            //                break;
            //            // TCN_SELCHANGE
            //            case -551:
            //                break;
            //            // TCN_SELCHANGING, process virtual keys in here.
            //            case -552:
            //                break;
            //        }
            //    }
            //}

            #endregion Tab Control Notification Messages

            base.WndProc(ref m);
            if (m.Msg == (int)User32.Msgs.WM_PARENTNOTIFY)
            {
                if ((ushort)(m.WParam.ToInt32() & 0xFFFF) == (int)User32.Msgs.WM_CREATE)
                {
                    var handle = FindUpDownControl();
                    if (handle != IntPtr.Zero)
                    {
                        if (_upDown32 != null)
                            _upDown32.ReleaseHandle();

                        _upDown32 = new UpDown32(handle);

                        if (_myScroller != null)
                        {
                            _myScroller.ScrollLeft -= ScrollLeft;
                            _myScroller.ScrollRight -= ScrollRight;
                            _myScroller.Dispose();
                            _myScroller = null;
                        }

                        _myScroller = new Scroller(_upDownStyle);
                        _myScroller.ScrollLeft += ScrollLeft;
                        _myScroller.ScrollRight += ScrollRight;

                        var parentHwnd = User32.GetParent(_myScroller.Handle);

                        if (parentHwnd != m.HWnd)
                            User32.SetParent(_myScroller.Handle, m.HWnd);

                        if (SelectedIndex == 0)
                            _myScroller._leftScroller.Enabled = false;
                        else if (SelectedIndex == TabCount - 1)
                            _myScroller._rightScroller.Enabled = false;

                        OnResize(EventArgs.Empty);
                    }
                }
            }
            else if (m.Msg == (int)User32.Msgs.WM_LBUTTONDOWN)
            {
                if (TabCount > 1)
                {
                    var selectingTabPage = OverTab();
                    if (selectingTabPage != null)
                    {
                        var index = TabPages.IndexOf(selectingTabPage);
                        if (index != SelectedIndex)
                        {
                            if (!selectingTabPage.Enabled)
                                m.Result = new IntPtr(1);
                            else
                            {
                                using (var e = new SelectedIndexChangingEventArgs(selectingTabPage, index))
                                {
                                    // Fire a Notification Event.
                                    OnSelectedIndexChanging(e);

                                    if (e.Cancel)
                                        m.Result = new IntPtr(1);
                                    else
                                    {
                                        selectingTabPage.preventClosing = true;
                                        SelectedTab = selectingTabPage;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (m.Msg == (int)User32.Msgs.WM_PAINT)
            {
                if (_upDown32 != null && !Multiline)
                {
                    if (TabCount > 1)
                    {
                        var width = 0;

                        for (var i = 0; i < TabCount; i++)
                            width += GetTabRect(i).Width;

                        if (width <= _myScroller.Left)
                            _myScroller.Visible = false;
                        else
                            _myScroller.Visible = true;
                    }
                    else if (TabCount <= 1)
                        _myScroller.Visible = false;
                }
            }
            else if (m.Msg == (int)User32.Msgs.WM_NCHITTEST)
            {
                if (m.Result.ToInt32() == User32._HT_TRANSPARENT)
                    m.Result = (IntPtr)User32._HT_CLIENT;
            }
        }
        protected override bool ProcessMnemonic(char charCode)
        {
            foreach (TabPageEx tabPage in TabPages)
            {
                if (IsMnemonic(charCode, tabPage.Text))
                {
                    if (!tabPage.Enabled)
                        return true;

                    using (var e = new SelectedIndexChangingEventArgs(tabPage, TabPages.IndexOf(tabPage)))
                    {
                        // Fire a Notification Event.
                        OnSelectedIndexChanging(e);

                        if (!e.Cancel)
                            SelectedTab = tabPage;

                        return true;
                    }
                }
            }

            return base.ProcessMnemonic(charCode);
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == (Keys.Tab | Keys.Control)) || (keyData == (Keys.Tab | Keys.Shift | Keys.Control)))
            {
                if (!OnNavigateTabPage((keyData & Keys.Shift) != Keys.Shift ? SelectedIndex + 1 : SelectedIndex - 1, true))
                {
                    msg.Result = new IntPtr(1);
                    return true;
                }
                return false;
            }
            switch (keyData)
            {
                // Selects Last TabPage
                case Keys.End:
                    if (!OnNavigateTabPage(TabCount - 1, false))
                    {
                        msg.Result = new IntPtr(1);
                        return true;
                    }
                    break;
                // Selects First TabPage
                case Keys.Home:
                    if (!OnNavigateTabPage(0, false))
                    {
                        msg.Result = new IntPtr(1);
                        return true;
                    }
                    break;
                // Selects the tab on the left side of the currently selected TabPage
                case Keys.Left:
                    if (!OnNavigateTabPage(SelectedIndex - 1, false))
                    {
                        msg.Result = new IntPtr(1);
                        return true;
                    }
                    break;
                // Selects the tab on the right side of the currently selected TabPage
                case Keys.Right:
                    if (!OnNavigateTabPage(SelectedIndex + 1, false))
                    {
                        msg.Result = new IntPtr(1);
                        return true;
                    }
                    break;

                case Keys.Insert:
                    if (_conditionBooleanArray[3] && MessageBox.Show("Do you want to insert a new tab page here?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        var tabPage = new TabPageEx();
                        Controls.Add(tabPage);
                        return true;
                    }
                    break;

                case Keys.Delete:
                    if (_conditionBooleanArray[3] && TabCount > 0)
                    {
                        if (MessageBox.Show("Do you want to remove the selected tab page?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            var removingTabPage = SelectedTab as TabPageEx;
                            if (removingTabPage != null && removingTabPage.IsClosable && removingTabPage.Enabled)
                            {
                                using (var e = new SelectedIndexChangingEventArgs(removingTabPage, SelectedIndex))
                                {
                                    // Fire a Notification Event.
                                    OnTabPageClosing(e);

                                    if (!e.Cancel)
                                    {
                                        TabPages.Remove(removingTabPage);
                                        SelectNextAvailableTabPage();
                                        return true;
                                    }
                                    MessageBox.Show("The operation was canceled by the user.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return true;
                                }
                            }
                            MessageBox.Show("The selected tab page could not be deleted!!!, it may be due to the following reasons;\r\n\r\n1.Tab page might be null or disposed by the application.\r\n2.Tab page might not be closable.\r\n3.Tab page might be disable.",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return true;
                        }
                    }
                    break;

                case Keys.Escape:
                    break;

                case Keys.F1:
                    break;
            }
            return false;
        }
 protected virtual void OnTabPageClosing(SelectedIndexChangingEventArgs e)
 {
     if (TabPageClosing != null)
         TabPageClosing(this, e);
 }
 protected virtual void OnSelectedIndexChanging(SelectedIndexChangingEventArgs e)
 {
     if (SelectedIndexChanging != null)
         SelectedIndexChanging(this, e);
 }
        /// <summary>
        /// Selects a tab page in the tab control.
        /// </summary>
        /// <param name="tabPageIndex">Index of the tab to select</param>
        /// <param name="wrap">Is command keys? (Control, Shift or Tab Keys.)</param>
        /// <returns>Returns TRUE to prevent the selection from changing, or FALSE to allow the selection to change.</returns>
        protected virtual bool OnNavigateTabPage(int tabPageIndex, bool wrap)
        {
            if ((tabPageIndex == SelectedIndex) || TabCount <= 1)
                return true;

            try
            {
                /* Control, Shift, Tab Keys */
                if (wrap)
                {
                    if (tabPageIndex > TabCount - 1)
                        tabPageIndex = 0;
                    else if (tabPageIndex < 0)
                        tabPageIndex = TabCount - 1;
                }

                var selectingTabPage = TabPages[tabPageIndex] as TabPageEx;
                if (selectingTabPage == null)
                    return true;
                if (!selectingTabPage.Enabled)
                    return true;

                using (var e = new SelectedIndexChangingEventArgs(selectingTabPage, tabPageIndex))
                {
                    // Fire a Notification Event.
                    OnSelectedIndexChanging(e);

                    if (!e.Cancel)
                    {
                        SelectedTab = selectingTabPage;
                        return false;
                    }

                    return true;
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                return true;
            }
        }
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (!_conditionBooleanArray[6])
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (!_conditionBooleanArray[4] ? TabCount > 1 : TabCount >= 1)
                    {
                        var closingTabPage = (TabPageEx)SelectedTab;
                        if (conditionRectangleArray[0].Contains(e.Location))
                        {
                            var flag = closingTabPage.IsClosable ? !closingTabPage.Enabled || closingTabPage.preventClosing : true;
                            if (!flag)
                            {
                                using (var te = new SelectedIndexChangingEventArgs(closingTabPage, SelectedIndex))
                                {
                                    // Fire a Notification Event.
                                    OnTabPageClosing(te);

                                    if (!te.Cancel)
                                    {
                                        SelectedTab.Dispose();
                                        if (DesignMode)
                                        {
                                            var selectionService = (ISelectionService)GetService(typeof(ISelectionService));
                                            selectionService.SetSelectedComponents(new IComponent[] { this }, SelectionTypes.Auto);
                                        }
                                    }

                                    Cursor.Position = PointToScreen(e.Location);
                                }
                            }
                            else
                                closingTabPage.preventClosing = false;
                        }
                        else
                            closingTabPage.preventClosing = false;
                    }
                }
            }

            base.OnMouseDoubleClick(e);
        }
        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (!_conditionBooleanArray[6])
            {
                if (e.Button == MouseButtons.Left)
                {
                    // IsCaptionVisible?
                    if (_conditionBooleanArray[1])
                    {
                        if (conditionRectangleArray[1].Contains(e.Location))
                        {
                            var contextMenu = new ContextMenuStrip();
                            var dropDownLocation = PointToScreen(new Point(conditionRectangleArray[1].X, conditionRectangleArray[1].Bottom));

                            using (var ea = new ContextMenuShownEventArgs(contextMenu, dropDownLocation))
                            {
                                // Fire a Notification Event.
                                OnContextMenuShown(ea);
                            }

                            goto Finalize;
                        }
                        if (TabCount > 0 && conditionRectangleArray[2].Contains(e.Location))
                        {
                            var closingTabPage = (TabPageEx)SelectedTab;
                            var flag = closingTabPage.IsClosable ? closingTabPage.Enabled : false;

                            if (flag)
                            {
                                using (var sea = new SelectedIndexChangingEventArgs(closingTabPage, SelectedIndex))
                                {
                                    // Fire a Notification Event.
                                    OnTabPageClosing(sea);

                                    if (!sea.Cancel)
                                    {
                                        TabPages.Remove(closingTabPage);
                                        SelectNextAvailableTabPage();
                                    }
                                    else
                                        MessageBox.Show("The operation was canceled by the user.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);

                                    Cursor.Position = PointToScreen(e.Location);
                                }
                            }

                            goto Finalize;
                        }
                    }

                    // IsDocumentTabStyle?
                    if (!_conditionBooleanArray[4] ? TabCount > 1 : TabCount >= 1)
                    {
                        var closingTabPage = (TabPageEx)SelectedTab;
                        if (conditionRectangleArray[0].Contains(e.Location))
                        {
                            var flag = closingTabPage.IsClosable ? !closingTabPage.Enabled || closingTabPage.preventClosing : true;
                            if (!flag)
                            {
                                using (var te = new SelectedIndexChangingEventArgs(closingTabPage, SelectedIndex))
                                {
                                    // Fire a Notification Event.
                                    OnTabPageClosing(te);

                                    if (!te.Cancel)
                                    {
                                        SelectedTab.Dispose();
                                        if (DesignMode)
                                        {
                                            var selectionService = (ISelectionService)GetService(typeof(ISelectionService));
                                            selectionService.SetSelectedComponents(new IComponent[] { this }, SelectionTypes.Auto);
                                        }
                                        else
                                            SelectNextAvailableTabPage();
                                    }

                                    Cursor.Position = PointToScreen(e.Location);
                                }
                            }
                            else
                                closingTabPage.preventClosing = false;
                        }
                        else
                            closingTabPage.preventClosing = false;
                    }
                }
            }

            Finalize: ;
            base.OnMouseClick(e);
        }
        protected virtual void OnContextMenuShown(ContextMenuShownEventArgs e)
        {
            ToolStripMenuItem menuItem;
            if (TabCount > 0)
            {
                menuItem = new ToolStripMenuItem("Close", Resources.delete_12x12, null, Keys.Control | Keys.C);
                menuItem.ImageScaling = ToolStripItemImageScaling.None;
                var closingTabPage = (TabPageEx)SelectedTab;
                menuItem.Enabled = closingTabPage.IsClosable && closingTabPage.Enabled;
                if (menuItem.Enabled)
                {
                    menuItem.Click += (sender, ea) =>
                    {
                        using (var sea = new SelectedIndexChangingEventArgs(closingTabPage, SelectedIndex))
                        {
                            // Fire a Notification Event.
                            OnTabPageClosing(sea);

                            if (!sea.Cancel)
                            {
                                TabPages.Remove(closingTabPage);
                                SelectNextAvailableTabPage();
                            }
                            else
                                MessageBox.Show("The operation was canceled by the user.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    };
                }

                e.ContextMenu.Items.Add(menuItem);

                if (TabCount > 1)
                {
                    menuItem = new ToolStripMenuItem("Close All But This", Resources.PushpinHS, null, Keys.Control | Keys.A);
                    menuItem.Click += (sender, ea) =>
                    {
                        // Iterate All TabPages in the collection.
                        for (var i = TabCount - 1; i >= 0; i--)
                        {
                            var currentTabPage = TabPages[i] as TabPageEx;
                            if (currentTabPage == null || !currentTabPage.IsClosable || i == SelectedIndex)
                                continue;

                            using (var sea = new SelectedIndexChangingEventArgs(currentTabPage, i))
                            {
                                // Fire a Notification Event.
                                OnTabPageClosing(sea);

                                if (!sea.Cancel)
                                    TabPages.Remove(currentTabPage);
                            }
                        }
                    };

                    e.ContextMenu.Items.Add(menuItem);
                    e.ContextMenu.Items.Add(new ToolStripSeparator());
                }
            }

            var availableMenuItems = new List<ToolStripMenuItem>();
            foreach (TabPageEx tab in TabPages)
            {
                menuItem = new ToolStripMenuItem(tab.ToString(), ImageList != null ? (tab.ImageIndex != -1 ? ImageList.Images[tab.ImageIndex] : null) : null, null, tab.Name);
                menuItem.Checked = true;
                menuItem.Click += (sender, ea) =>
                {
                    HideTab((TabPageEx)TabPages[((ToolStripItem)sender).Name]);
                };

                availableMenuItems.Add(menuItem);
            }

            if (_tabPageExPool != null)
            {
                foreach (TabPageEx tab in _tabPageExPool)
                {
                    menuItem = new ToolStripMenuItem(tab.ToString(), ImageList != null ? (tab.ImageIndex != -1 ? ImageList.Images[tab.ImageIndex] : null) : null, null, tab.Name);
                    menuItem.Click += (sender, ea) =>
                    {
                        ShowTab(_tabPageExPool[((ToolStripItem)sender).Name]);
                    };

                    availableMenuItems.Add(menuItem);
                }
            }

            if (availableMenuItems.Count > 0)
            {
                availableMenuItems.Sort((p1, p2) => String.Compare(p1.Text, p2.Text, StringComparison.Ordinal));

                try
                {
                    var availableItem = availableMenuItems.Cast<ToolStripItem>().ToArray();

                    menuItem = new ToolStripMenuItem("Available Tab Pages", Resources.InsertTabControlHS, availableItem);
                    e.ContextMenu.Items.Add(menuItem);
                    availableMenuItems.Clear();
                }
                catch
                {
                    ;
                }
            }

            if (ContextMenuShown != null)
                ContextMenuShown(this, e);

            e.ContextMenu.Show(e.MenuLocation);
        }
        private void SelectNextAvailableTabPage()
        {
            if (this.TabCount <= 1)
                return;

            using (SelectedIndexChangingEventArgs e = new SelectedIndexChangingEventArgs((TabPageEx)SelectedTab, 0))
            {
                // Fire a Notification Event.
                OnSelectedIndexChanging(e);

                if (e.Cancel)
                {
                    for (int i = 1; OnNavigateTabPage(i, false) && i < this.TabCount; i++) ;
                }
            }
        }