Example #1
0
 protected virtual void OnTabStripItemChanged(TabStripItem tabItem)
 {
     if (TabStripItemChanged != null)
     {
         TabStripItemChanged(tabItem);
     }
 }
Example #2
0
        void CalculateVisibility(TabStripItem lastAdded)
        {
            Rectangle selectedButton = Rectangle.Empty;

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Trimming      = StringTrimming.EllipsisCharacter;
            sf.FormatFlags  |= StringFormatFlags.NoWrap;

            int right = 0;

            _VisibleCount = 0;

            using (Graphics _Gfx = this.CreateGraphics())
            {
                Control[] ctls = new Control[this.Controls.Count + 1];

                this.Controls.CopyTo(ctls, 0);

                ctls[this.Controls.Count] = lastAdded;

                for (int i = 0; i < ctls.Length; i++)
                {
                    TabStripItem current = (TabStripItem)ctls[i];

                    Font currentFont = this.Font;

                    if ((current.DrawState &= DrawItemState.Selected) == DrawItemState.Selected)
                    {
                        currentFont = new Font(this.Font, FontStyle.Bold);
                    }

                    Size textSize = _Gfx.MeasureString(current.Text, currentFont, new SizeF(200, 10), sf).ToSize();

                    textSize.Width += 20;

                    Rectangle buttonRect = new Rectangle(right, 3, textSize.Width, 17);

                    current.StripRect = buttonRect;

                    right += textSize.Width;

                    if (right >= _StripButtonRect.Width)
                    {
                        break;
                    }

                    _VisibleCount = i;
                }
            }
        }
Example #3
0
        void loadMenuItems()
        {
            _ContextDocsList.Items.Clear();


            for (int i = 0; i < this.Controls.Count; i++)
            {
                TabStripItem item = (TabStripItem)this.Controls[i];

                ToolStripMenuItem tItem = new ToolStripMenuItem(item.Text);

                tItem.Tag = item;

                _ContextDocsList.Items.Add(tItem);
            }
        }
Example #4
0
        protected override void OnControlAdded(ControlEventArgs e)
        {
            if (!(e.Control is TabStripItem))
            {
                throw new Exception("TabStrip accept only TabStripItem");
            }

            base.OnControlAdded(e);

            if (this.SelectedItem == null)
            {
                this.SelectedItem = (TabStripItem)e.Control;
            }
            else
            {
                e.Control.Visible = false;
            }

            CalculateVisibility((TabStripItem)e.Control);

            this.Invalidate();
        }
Example #5
0
        protected override void OnControlAdded(ControlEventArgs e)
        {
            if (!(e.Control is TabStripItem))
                throw new Exception("TabStrip accept only TabStripItem");

            base.OnControlAdded(e);

            if (this.SelectedItem == null)
                this.SelectedItem = (TabStripItem)e.Control;
            else
                e.Control.Visible = false;

            CalculateVisibility((TabStripItem)e.Control);

            this.Invalidate();
        }
Example #6
0
 void SelectItem(TabStripItem tabItem)
 {
     tabItem.Visible    = true;
     tabItem.DrawState |= DrawItemState.Selected;
 }
Example #7
0
 void UnSelectItem(TabStripItem tabItem)
 {
     tabItem.Visible   = false;
     tabItem.DrawState = DrawItemState.None;
 }
Example #8
0
 public void RemoveTab(TabStripItem tabItem)
 {
     this.Controls.Remove(tabItem);
 }
Example #9
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button != MouseButtons.Left)
            {
                return;
            }



            if (_MenuGlyph.GlyphRect.Contains(e.Location))
            {
                loadMenuItems();
                if (_ContextDocsList.Visible == false)
                {
                    _ContextDocsList.Show(this, new Point(e.X, _MenuGlyph.GlyphRect.Bottom));
                }
            }

            if (_CloseButton.CrossRect.Contains(e.Location) && this.SelectedItem.CanClose)
            {
                TabStripItemClosingEventArgs evt = new TabStripItemClosingEventArgs(_SelectedItem);

                OnTabStripItemClosing(evt);

                if (!evt.Cancel)
                {
                    this.Controls.Remove(_SelectedItem);

                    this.OnTabStripItemClosing(EventArgs.Empty);
                }
            }

            this.Invalidate();

            TabStripItem selected = null;

            for (int i = 0; i < this.Controls.Count; i++)
            {
                TabStripItem current = (TabStripItem)this.Controls[i];

                if (current.StripRect.Contains(e.Location))
                {
                    current.DrawState |= DrawItemState.Selected;

                    if (current.StripRect.Right > _StripButtonRect.Right)
                    {
                        break;
                    }
                    else
                    {
                        selected = current;
                        break;
                    }
                }
            }

            if (selected == null)
            {
                return;
            }

            this.SelectedItem = selected;

            this.Invalidate();
        }
Example #10
0
        //private int CalculateVisibilityCount()
        //{
        //    for (int i = 0; i < this.Controls.Count; i++)
        //    {
        //    }
        //}

        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle borderRc = base.ClientRectangle;

            borderRc.Width--;
            borderRc.Height--;

            //ControlPaint.DrawVisualStyleBorder(e.Graphics, borderRc);
            e.Graphics.DrawRectangle(SystemPens.ControlDark, borderRc);

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            float right = 10;

            RectangleF selectedButton = Rectangle.Empty;

            StringFormat sf = new StringFormat();

            // sf.LineAlignment = StringAlignment.Center;
            sf.Trimming     = StringTrimming.EllipsisCharacter;
            sf.FormatFlags |= StringFormatFlags.NoWrap;


            for (int i = 0; i < this.Controls.Count; i++)
            {
                TabStripItem current = (TabStripItem)this.Controls[i];

                Font currentFont = this.Font;

                if ((current.DrawState &= DrawItemState.Selected) == DrawItemState.Selected)
                {
                    currentFont = new Font(this.Font, FontStyle.Bold);
                }

                SizeF textSize = e.Graphics.MeasureString(current.Text, currentFont, new SizeF(200, 10), sf);

                textSize.Width += 20;

                RectangleF buttonRect = new RectangleF(right, 3, textSize.Width, 17);

                current.StripRect = buttonRect;

                right += textSize.Width;

                if (right > _StripButtonRect.Width)
                {
                    break;
                }

                DrawButton(e.Graphics, buttonRect, current.DrawState, this.Controls.GetChildIndex(current));

                PointF textLoc = new PointF(buttonRect.Left + buttonRect.Height - 2
                                            , buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2);

                RectangleF textRect = buttonRect;

                textRect.Location = textLoc;

                textRect.X -= 2;
                textRect.Y -= 2;

                textRect.Width = (float)buttonRect.Width - (textRect.Left - buttonRect.Left);

                textRect.Height = textSize.Height + currentFont.Size / 2;

                if ((current.DrawState &= DrawItemState.Selected) == DrawItemState.Selected)
                {
                    e.Graphics.DrawString(current.Text, currentFont, new SolidBrush(this.ForeColor), textRect, sf);
                }
                else
                {
                    e.Graphics.DrawString(current.Text, currentFont, new SolidBrush(this.ForeColor), textRect, sf);
                }

                if (current == _SelectedItem)
                {
                    selectedButton = buttonRect;
                }



                _VisibleCount = i;

                if (right > _StripButtonRect.Width)
                {
                    break;
                }
            }

            if (_SelectedItem != null)
            {
                if (this.Controls.GetChildIndex(_SelectedItem) != 0)
                {
                    e.Graphics.DrawLine(SystemPens.ControlDark, 0, _SelectedItem.StripRect.Bottom - 1,
                                        _SelectedItem.StripRect.Left - 10, _SelectedItem.StripRect.Bottom - 1);
                }

                e.Graphics.DrawLine(SystemPens.ControlDark, _SelectedItem.StripRect.Right, _SelectedItem.StripRect.Bottom - 1,
                                    this.ClientSize.Width, _SelectedItem.StripRect.Bottom - 1);

                e.Graphics.DrawLine(Pens.White, _SelectedItem.StripRect.Left - 9,
                                    _SelectedItem.StripRect.Bottom - 1, _SelectedItem.StripRect.Right,
                                    _SelectedItem.StripRect.Bottom - 1);
            }

            if (_SelectedItem == null)
            {
                return;
            }

            _CloseButton.Activated = _SelectedItem.CanClose;

            _MenuGlyph.DrawGlyph(e.Graphics);

            if (_SelectedItem.CanClose)
            {
                _CloseButton.DrawCross(e.Graphics);
            }
        }
Example #11
0
 public void AddTab(TabStripItem tabItem)
 {
     this.Controls.Add(tabItem);
 }
Example #12
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button != MouseButtons.Left)
                return;

            if (_MenuGlyph.GlyphRect.Contains(e.Location))
            {
                loadMenuItems();
                if (_ContextDocsList.Visible == false)
                    _ContextDocsList.Show(this, new Point(e.X, _MenuGlyph.GlyphRect.Bottom));
            }

            if (_CloseButton.CrossRect.Contains(e.Location) && this.SelectedItem.CanClose )
            {
                TabStripItemClosingEventArgs evt = new TabStripItemClosingEventArgs(_SelectedItem);

                OnTabStripItemClosing(evt);

                if (!evt.Cancel)
                {
                    this.Controls.Remove(_SelectedItem);

                    this.OnTabStripItemClosing(EventArgs.Empty);
                }
            }

            this.Invalidate();

            TabStripItem selected = null;

            for (int i = 0; i < this.Controls.Count; i++)
            {
                TabStripItem current = (TabStripItem)this.Controls[i];

                if (current.StripRect.Contains(e.Location))
                {
                    current.DrawState |= DrawItemState.Selected;

                    if (current.StripRect.Right > _StripButtonRect.Right)
                    {
                        break;
                    }
                    else
                    {
                        selected = current;
                        break;
                    }
                }
            }

            if (selected == null)
                return;

            this.SelectedItem = selected;

            this.Invalidate();
        }
Example #13
0
 void _ContextDocsList_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     this.SelectedItem = (TabStripItem)e.ClickedItem.Tag;
 }
Example #14
0
 protected virtual void OnTabStripItemChanged(TabStripItem tabItem)
 {
     if (TabStripItemChanged != null)
         TabStripItemChanged(tabItem);
 }
Example #15
0
 public TabStripItemClosingEventArgs(TabStripItem item)
 {
     _item = item;
 }
Example #16
0
 void UnSelectItem(TabStripItem tabItem)
 {
     tabItem.Visible = false;
     tabItem.DrawState = DrawItemState.None;
 }
Example #17
0
 void SelectItem(TabStripItem tabItem)
 {
     tabItem.Visible = true;
     tabItem.DrawState |= DrawItemState.Selected;
 }
Example #18
0
 public void RemoveTab(TabStripItem tabItem)
 {
     this.Controls.Remove(tabItem);
 }
Example #19
0
 public void AddTab(TabStripItem tabItem)
 {
     this.Controls.Add(tabItem);
 }
Example #20
0
        void CalculateVisibility(TabStripItem lastAdded)
        {
            Rectangle selectedButton = Rectangle.Empty;

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Trimming = StringTrimming.EllipsisCharacter;
            sf.FormatFlags |= StringFormatFlags.NoWrap;

            int right = 0;

            _VisibleCount = 0;

            using (Graphics _Gfx = this.CreateGraphics())
            {

                Control[] ctls = new Control[this.Controls.Count+1];

                this.Controls.CopyTo(ctls, 0);

                ctls[this.Controls.Count] = lastAdded;

                for (int i = 0; i < ctls.Length; i++)
                {
                    TabStripItem current = (TabStripItem)ctls[i];

                    Font currentFont = this.Font;

                    if ((current.DrawState &= DrawItemState.Selected) == DrawItemState.Selected)
                    {
                        currentFont = new Font(this.Font, FontStyle.Bold);
                    }

                    Size textSize = _Gfx.MeasureString(current.Text, currentFont, new SizeF(200, 10), sf).ToSize();

                    textSize.Width += 20;

                    Rectangle buttonRect = new Rectangle(right, 3, textSize.Width, 17);

                    current.StripRect = buttonRect;

                    right += textSize.Width;

                    if (right >= _StripButtonRect.Width)
                        break;

                    _VisibleCount = i;
                }
            }
           
        }
Example #21
0
 public TabStripItemClosingEventArgs(TabStripItem item)
 {
     _item = item;
 }
Example #22
0
 protected override void OnControlRemoved(ControlEventArgs e)
 {
     base.OnControlRemoved(e);
     if (this.Controls.Count > 0)
         this.SelectedItem = (TabStripItem)this.Controls[this.Controls.Count - 1];
     else
         this.SelectedItem = null;
 }