A class to contain the information regarding the YaTabControl.TabClosing event.
Inheritance: System.EventArgs
コード例 #1
0
 /// <summary>
 /// Fires the <see cref="TabClosing" /> event.
 /// </summary>
 /// <param name="e">
 /// Some <see cref="TabClosingEventArgs"/> for the event.
 /// </param>
 protected virtual void OnTabClosing(TabClosingEventArgs e)
 {
     if (this.Controls.Count <= 2) e.Cancel = true;
     if(TabClosing != null)
     {
         TabClosing(this, e);
     }
 }
コード例 #2
0
        /// <summary>
        /// Overridden. Inherited from <see cref="Control"/>.
        /// </summary>
        /// <param name="mea">
        /// See <see cref="Control.OnMouseDown(MouseEventArgs)"/>.
        /// </param>
        protected override void OnMouseDown(MouseEventArgs mea)
        {
            base.OnMouseDown(mea);

            Point p;

            //see if user clicked on close button
            p = mea.Location;
            for (int i = 0; i <= yaLastVisibleTabIndex; i++)
            {
                var tag = this.Controls[i].Tag;
                if (tag != null && tag.ToString() == "NEW_TAB")
                {
                    continue;
                }

                var tabRectangle = GetTabRect(i);
                var clickRectangle = GetRectangleClose(tabRectangle, 2);    //slightly larger target area for the mouse (x image padding)

                if (clickRectangle.Contains(p))
                {
                    var etc = new TabClosingEventArgs();
                    OnTabClosing(etc);
                    if (!etc.Cancel)
                    {
                        Controls.RemoveAt(i);
                        InU();
                        this.SelectedIndex = i - 1;
                        OnTabChanged(new EventArgs());
                        return;
                    }
                }
            }

            //done checking for close event
            p = new Point(mea.X - 2 * yaMargin, mea.Y);
            switch (yaTabDock)
            {
                case DockStyle.Bottom:
                    p.Y -= yaClientRectangle.Height;
                    break;
                case DockStyle.Left:
                    p.Y = mea.X;
                    p.X = Height - mea.Y;
                    break;
                case DockStyle.Right:
                    p.Y = Width - mea.X;
                    p.X = mea.Y;
                    break;
            }
            if (p.Y > yaMargin && p.Y < Convert.ToInt32(yaTabSpan + 3.0f * yaMargin))
            {
                if ((yaShowScrollButtons == YaScrollButtonStyle.Always || (yaShowScrollButtons == YaScrollButtonStyle.Auto && yaTotalTabSpan > calcWidth)) && p.X >= rightArrow[0].X - 3 * yaMargin)
                {
                    if (canScrollRight)
                    {
                        yaKeepScrolling = true;
                        ScrollerThread st = new ScrollerThread(2, this);
                        Thread t = new Thread(new ThreadStart(st.ScrollIt));
                        t.Start();
                    }
                }
                else if ((yaShowScrollButtons == YaScrollButtonStyle.Always || (yaShowScrollButtons == YaScrollButtonStyle.Auto && yaTotalTabSpan > calcWidth)) && p.X >= leftArrow[2].X - 3 * yaMargin)
                {
                    if (canScrollLeft)
                    {
                        yaKeepScrolling = true;
                        ScrollerThread st = new ScrollerThread(-2, this);
                        Thread t = new Thread(new ThreadStart(st.ScrollIt));
                        t.Start();
                    }
                }
                else
                {
                    int t = -Convert.ToInt32(yaTabLeftDif);
                    for (int i = 0; i <= yaLastVisibleTabIndex; i++)
                    {
                        if (p.X >= t && p.X < t + Convert.ToInt32(yaTabLengths[i]))
                        {
                            SelectedIndex = i;
                            break;
                        }
                        t += Convert.ToInt32(yaTabLengths[i]);
                    }
                }
            }
        }