Beispiel #1
0
        public TabButton(TabButton button)
        {
            Text       = button.Text;
            ImageIndex = button.ImageIndex;

            ActiveForeColor  = button.ActiveForeColor;
            ActiveBackColor  = button.ActiveBackColor;
            ActiveFontFamily = button.ActiveFontFamily;
            ActiveFontStyle  = button.ActiveFontStyle;

            InactiveForeColor  = button.InactiveForeColor;
            InactiveBackColor  = button.InactiveBackColor;
            InactiveFontFamily = button.InactiveFontFamily;
            InactiveFontStyle  = button.InactiveFontStyle;
        }
Beispiel #2
0
            /// <summary>
            /// コレクションから index 番目のボタンを削除します。
            /// </summary>
            /// <param name="index">削除するボタンのインデックス。</param>
            public void RemoveAt(int index)
            {
                if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                TabButton button = this[index];

                button.parent    = null;
                button.imageList = null;

                innerList.RemoveAt(index);
                parent.UpdateButtons();
            }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (e.Button == MouseButtons.Left)
            {
                TabButton button = GetButtonAt(new Point(e.X, e.Y));

                if (button != null && focused != null && focused != button)
                {
                    buttons.InsertBefore(focused, button);
                }
            }
            focused = null;
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Left)
            {
                TabButton button = GetButtonAt(new Point(e.X, e.Y));

                if (button != null)
                {
                    focused = button;
                    SetSelected(focused);
                }
            }
        }
Beispiel #5
0
            /// <summary>
            /// コレクション内の index 番目に button を挿入します。
            /// </summary>
            /// <param name="index">0 から始まるコレクション内インデックス。</param>
            /// <param name="button">index 番目に挿入されるボタン。</param>
            public void Insert(int index, TabButton button)
            {
                if (index < 0 || index > Count)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                if (button.parent != null)
                {
                    throw new ArgumentException("このボタンは既に他のタブコントロールに登録されています。");
                }

                innerList.Insert(index, button);

                button.parent    = parent;
                button.imageList = parent.ImageList;

                parent.UpdateButtons();
            }
Beispiel #6
0
            /// <summary>
            /// コレクションの末尾に button を追加します。
            /// </summary>
            /// <param name="button"></param>
            /// <returns></returns>
            public int Add(TabButton button)
            {
                if (button == null)
                {
                    throw new ArgumentNullException("button");
                }

                if (button.parent != null)
                {
                    throw new ArgumentException("このボタンは既に他のタブコントロールに登録されています。");
                }

                int index = innerList.Add(button);

                button.parent    = parent;
                button.imageList = parent.ImageList;
                parent.UpdateButtons();

                return(index);
            }
        private void SetSelected(TabButton button)
        {
            if (selected != null)
            {
                Region region = new Region(selected.Bounds);
                region.Union(button.Bounds);

                selected = button;
                Invalidate(region);
            }
            else
            {
                selected = button;
                Invalidate(selected.Bounds);
            }

            Update();

            OnSelectedChanged(selected);
        }
Beispiel #8
0
            /// <summary>
            /// button の位置を target の前に移動します。
            /// </summary>
            /// <param name="target"></param>
            /// <param name="button"></param>
            public void InsertBefore(TabButton target, TabButton button)
            {
                if (target == button)
                {
                    return;
                }

                if (target.parent == null)
                {
                    throw new ArgumentException("target に親が存在しません。");
                }

                if (button.parent == null)
                {
                    throw new ArgumentException("button に親が存在しません");
                }

                if (target.parent != button.parent)
                {
                    throw new ArgumentException("target と button の親が違います。");
                }

                int newIndex;

                if (target.Index < button.Index)
                {
                    newIndex = target.Index;
                }
                else
                {
                    newIndex = target.Index - 1;
                }

                innerList.Remove(button);
                innerList.Insert(newIndex, button);

                parent.UpdateButtons();
            }
        /// <summary>
        /// 指定したボタンのサイズを返します。
        /// </summary>
        /// <param name="g"></param>
        /// <param name="button"></param>
        /// <returns></returns>
        private Size GetButtonSize(Graphics g, TabButton button)
        {
            Font tempFont = new Font(
                button.IsSelected ? button.ActiveFontFamily : button.InactiveFontFamily, Font.Size,
                button.IsSelected ? button.ActiveFontStyle : button.InactiveFontStyle);

            Size itemSize = g.MeasureString(button.Text, tempFont).ToSize();

            tempFont.Dispose();

            // ちょっとずれるので適当に調整
            itemSize.Width  += 8;
            itemSize.Height += 5;

            // アイコンが存在すればアイコンサイズを足す
            if (button.ImageIndex != -1 && imageList != null)
            {
                Size imageSize = imageList.ImageSize;
                itemSize.Width += imageSize.Width;
                itemSize.Height = Math.Max(itemSize.Height, imageSize.Height);
            }

            return(itemSize);
        }
Beispiel #10
0
 public int IndexOf(TabButton button)
 {
     return(innerList.IndexOf(button));
 }
Beispiel #11
0
 public bool Contains(TabButton button)
 {
     return(innerList.Contains(button));
 }
        private void DrawButton(Graphics g, TabButton button)
        {
            StringFormat format = StringFormat.GenericDefault;

            format.Alignment     = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            format.FormatFlags   = StringFormatFlags.NoWrap;

            Rectangle bounds  = button.Bounds;
            Size      imgSize = (imageList != null) ? imageList.ImageSize : new Size(0, 0);

            int       margin    = (button.ImageIndex != -1) ? 5 : 0;
            Rectangle imageRect = new Rectangle(bounds.X + margin, bounds.Y + bounds.Height / 2 - imgSize.Height / 2, imgSize.Width, imgSize.Height);
            Rectangle textRect  = new Rectangle(imageRect.Right, bounds.Y, bounds.Width - imageRect.Width - margin, bounds.Height);

            // 境界線を描画
            DrawButtonBorder(g, button);

            // ホットな背景色を描画
            if (hotTrack && button.Equals(hot))
            {
                Rectangle rc   = button.Bounds;
                Size      size = SystemInformation.Border3DSize;

                rc.Width  -= 2;
                rc.Height -= 2;

                using (Brush b = new SolidBrush(Color.FromArgb(50, HotTrackColor)))
                    g.FillRectangle(b, rc);

                using (Pen pen = new Pen(HotTrackColor))
                    g.DrawRectangle(pen, rc);
            }
            else
            {
                // 通常の背景色を描画
                using (Brush brush = new SolidBrush(button.IsSelected ?
                                                    button.ActiveBackColor : button.InactiveBackColor))
                {
                    Rectangle rc     = button.Bounds;
                    Size      border = SystemInformation.Border3DSize;

                    rc.Inflate(-border.Width, -border.Height);

                    g.FillRectangle(brush, rc);
                }
            }

            // アイコンを描画
            if (imageList != null &&
                button.ImageIndex >= 0 && button.ImageIndex < imageList.Images.Count)
            {
                g.DrawImage(imageList.Images[button.ImageIndex], imageRect);
            }

            // テキストを描画
            Brush foreBrush = new SolidBrush(button.IsSelected ?
                                             button.ActiveForeColor : button.InactiveForeColor);

            Font textFont = button.IsSelected ?
                            new Font(button.ActiveFontFamily, Font.Size, button.ActiveFontStyle) :
                            new Font(button.InactiveFontFamily, Font.Size, button.InactiveFontStyle);

            g.DrawString(button.Text, textFont, foreBrush, textRect, format);

            textFont.Dispose();
            foreBrush.Dispose();
        }