示例#1
0
        public CaptionButtonInfo AddButton(string text, Image image)
        {
            CaptionButtonInfo cbi = new CaptionButtonInfo(text, image);

            AddButton(cbi);
            return(cbi);
        }
示例#2
0
 protected virtual void OnButtonClick(CaptionButtonInfo button)
 {
     if (ButtonClick != null)
     {
         ButtonClick(button, EventArgs.Empty);
     }
 }
示例#3
0
        void InvalidateButton(CaptionButtonInfo button)
        {
            if (button == null)
            {
                return;
            }

            Invalidate(button.Bounds);
        }
示例#4
0
        void OnMouseDownButtonChanged(CaptionButtonInfo old)
        {
            if (old != null)
            {
                InvalidateButton(old);
            }

            if (MouseDownButton != null)
            {
                InvalidateButton(MouseDownButton);
            }
        }
示例#5
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                MouseDownButton = HitTest(e.X, e.Y);
                if (MouseDownButton != null)
                {
                    Capture = true;
                }
            }
        }
示例#6
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (MouseDownButton != null && MouseDownButton == HitTest(e.X, e.Y))
            {
                MouseDownButton.NotifyClick();

                OnButtonClick(MouseDownButton);
            }

            MouseDownButton = null;
            Capture         = false;
        }
示例#7
0
        protected virtual void DrawButton(PaintEventArgs e, CaptionButtonInfo button)
        {
            if (button == null)
            {
                throw new ArgumentNullException();
            }

            if (button == MouseHoverButton || button == MouseDownButton)
            {
                VisualStyleElement vse = null;
                ButtonState        bs  = ButtonState.Normal;
                if (button == MouseDownButton)
                {
                    vse = VisualStyleElement.Button.PushButton.Pressed;
                    bs  = ButtonState.Pushed;
                }
                else if (button == MouseHoverButton)
                {
                    vse = VisualStyleElement.Button.PushButton.Normal;
                    bs  = ButtonState.Normal;
                }

                if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(vse))
                {
                    var renderer = new VisualStyleRenderer(vse);
                    renderer.DrawBackground(e.Graphics, button.Bounds);
                }
                else
                {
                    ControlPaint.DrawButton(e.Graphics, button.Bounds, bs);
                }
            }

            if (button.Image != null)
            {
                var rectangle = button.Bounds;
                e.Graphics.DrawImage(button.Image,
                                     new Rectangle(rectangle.X + (rectangle.Width - button.Image.Width) / 2,
                                                   rectangle.Y + (rectangle.Height - button.Image.Height) / 2,
                                                   button.Image.Width,
                                                   button.Image.Height),
                                     0, 0, button.Image.Width, button.Image.Height,
                                     GraphicsUnit.Pixel);
            }
        }
示例#8
0
        public bool RemoveButton(CaptionButtonInfo button)
        {
            if (button == null)
            {
                throw new ArgumentNullException();
            }

            if (Buttons.Contains(button))
            {
                Buttons = Buttons.Where(b => b != button).ToArray();
                ResetControlsBounds();
                Invalidate();
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#9
0
        void OnMouseHoverButtonChanged(CaptionButtonInfo old)
        {
            if (old != null)
            {
                InvalidateButton(old);
            }

            if (MouseHoverButton != null)
            {
                InvalidateButton(MouseHoverButton);
            }

            if (MouseHoverButton != null)
            {
                ShowToolTipText(Lang._(MouseHoverButton.Text));
            }
            else
            {
                ShowToolTipText(null);
            }
        }
示例#10
0
        public CaptionButtonInfo AddButton(CaptionButtonInfo button)
        {
            if (button == null)
            {
                throw new ArgumentNullException();
            }

            List <CaptionButtonInfo> list = new List <CaptionButtonInfo>();

            if (!Buttons.IsNullOrEmpty())
            {
                list.AddRange(Buttons);
            }
            list.Add(button);
            //list.Sort();
            Buttons = list.ToArray();

            ResetControlsBounds();
            Invalidate();

            return(button);
        }
示例#11
0
 public CaptionButtonClickEventArgs(CaptionButtonInfo button)
 {
     Button = button;
 }