⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wndlessmixedlabel.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace Imps.Client.Pc.WndlessControls
{
    using System;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class WndlessMixedLabel : WndlessLabel
    {
        private ContextMenuStrip _contextMenu;
        private static Font _fontForDropDownIcon = new Font("Times New Roman", 7.5f, FontStyle.Regular);
        private bool _hoverButton;
        private ShowSeparatorMode _showSepMode;
        private static Size _szOfDropDownIcon = TextRenderer.MeasureText("▼", _fontForDropDownIcon);
        private Image dropDownIcon;
        private const string DropDownIconText = "▼";

        public event EventHandler DropDownIconClick;

        public event EventHandler LabelClick;

        public WndlessMixedLabel()
        {
            base.Margin = new Padding(4);
            this._showSepMode = ShowSeparatorMode.Hover;
            this._hoverButton = false;
        }

        private void _contextMenu_VisibleChanged(object sender, EventArgs e)
        {
            base.Invalidate();
        }

        protected virtual void OnDropDownIconClick(EventArgs e)
        {
            EventHandler dropDownIconClick = this.DropDownIconClick;
            if (dropDownIconClick != null)
            {
                dropDownIconClick(this, e);
            }
            else
            {
                ContextMenuStrip strip = this._contextMenu;
                if (strip != null)
                {
                    strip.Show(base.OwnerControl, new Point(base.Left, base.Bottom));
                }
            }
        }

        protected virtual void OnLabelClick(EventArgs e)
        {
            EventHandler labelClick = this.LabelClick;
            if (labelClick != null)
            {
                labelClick(this, e);
            }
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (e.X < (base.Right - _szOfDropDownIcon.Width))
                {
                    this.OnLabelClick(EventArgs.Empty);
                }
                else
                {
                    this.OnDropDownIconClick(EventArgs.Empty);
                }
            }
            base.OnMouseClick(e);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            this._hoverButton = false;
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (this.ShowSeparator == ShowSeparatorMode.HoverButton)
            {
                this.HoverButton = this.ButtonRectangle.Contains(e.get_Location());
            }
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            float x;
            RectangleF rect;
            base.OnPaintBackground(e);
            Rectangle bounds = base.Bounds;
            float top = bounds.Top;
            float bottom = bounds.Bottom;
            if (this.dropDownIcon != null)
            {
                x = (bounds.Right - this.dropDownIcon.Width) - 6;
                rect = new RectangleF(x, top + ((base.Height - this.dropDownIcon.Height) / 2), (float) this.dropDownIcon.Width, (float) this.dropDownIcon.Height);
            }
            else
            {
                x = bounds.Right - _szOfDropDownIcon.Width;
                rect = new RectangleF(x += 1f, top + ((base.Height - _szOfDropDownIcon.Height) / 2), (float) _szOfDropDownIcon.Width, (float) _szOfDropDownIcon.Height);
            }
            if (base.Enabled)
            {
                if (this.dropDownIcon != null)
                {
                    e.Graphics.DrawImage(this.dropDownIcon, rect);
                }
                else
                {
                    e.Graphics.DrawString("▼", _fontForDropDownIcon, new SolidBrush(base.ForeColor), rect);
                }
            }
            else if (this.dropDownIcon != null)
            {
                ControlPaint.DrawImageDisabled(e.Graphics, this.dropDownIcon, (int) rect.X, (int) rect.Y, Color.Transparent);
            }
            else
            {
                ControlPaint.DrawStringDisabled(e.Graphics, "▼", _fontForDropDownIcon, base.BackColor, rect, null);
            }
            bool mouseHovered = false;
            switch (this.ShowSeparator)
            {
                case ShowSeparatorMode.Hover:
                    mouseHovered = base.MouseHovered;
                    break;

                case ShowSeparatorMode.HoverButton:
                    mouseHovered = this._hoverButton;
                    break;

                case ShowSeparatorMode.Aways:
                    mouseHovered = true;
                    break;
            }
            if (mouseHovered || base.MouseHovered)
            {
                Pen white = new Pen(base.BorderColor);
                Rectangle rectangle2 = base.Bounds;
                rectangle2.Height--;
                rectangle2.Width--;
                if (base.MouseHovered)
                {
                    e.Graphics.DrawRectangle(white, rectangle2);
                }
                if (mouseHovered)
                {
                    x -= 1f;
                    bottom = rectangle2.Bottom;
                    e.Graphics.DrawLine(white, x, top, x, bottom);
                }
                white = Pens.White;
                if (base.MouseHovered)
                {
                    rectangle2.X++;
                    rectangle2.Y++;
                    rectangle2.Width -= 2;
                    rectangle2.Height -= 2;
                    e.Graphics.DrawRectangle(white, rectangle2);
                }
                if (mouseHovered)
                {
                    x += 1f;
                    e.Graphics.DrawLine(white, x, top += 1f, x, bottom -= 1f);
                }
            }
        }

        protected Rectangle ButtonRectangle
        {
            get
            {
                Rectangle bounds = base.Bounds;
                bounds.X = bounds.Right - _szOfDropDownIcon.Width;
                bounds.Width = _szOfDropDownIcon.Width;
                return bounds;
            }
        }

        public override Rectangle ClientRectangle
        {
            get
            {
                Rectangle clientRectangle = base.ClientRectangle;
                clientRectangle.Width -= _szOfDropDownIcon.Width;
                return clientRectangle;
            }
        }

        public ContextMenuStrip ContextMenu
        {
            get
            {
                return this._contextMenu;
            }
            set
            {
                if (this._contextMenu != null)
                {
                    this._contextMenu.VisibleChanged -= new EventHandler(this._contextMenu_VisibleChanged);
                }
                this._contextMenu = value;
                if (this._contextMenu != null)
                {
                    this._contextMenu.VisibleChanged += new EventHandler(this._contextMenu_VisibleChanged);
                }
            }
        }

        protected override bool DoInvalidateWhenHover
        {
            get
            {
                return true;
            }
        }

        public Image DropDownIcon
        {
            get
            {
                return this.dropDownIcon;
            }
            set
            {
                this.dropDownIcon = value;
                base.Invalidate();
            }
        }

        protected bool HoverButton
        {
            get
            {
                return this._hoverButton;
            }
            set
            {
                if (this._hoverButton != value)
                {
                    this._hoverButton = value;
                    base.Invalidate();
                }
            }
        }

        public override Size PreferredClientSize
        {
            get
            {
                Size preferredClientSize = base.PreferredClientSize;
                preferredClientSize.Width += _szOfDropDownIcon.Width;
                if (preferredClientSize.Height < _szOfDropDownIcon.Height)
                {
                    preferredClientSize.Height = _szOfDropDownIcon.Height;
                }
                return preferredClientSize;
            }
        }

        public ShowSeparatorMode ShowSeparator
        {
            get
            {
                return this._showSepMode;
            }
            set
            {
                this._showSepMode = value;
            }
        }

        public enum ShowSeparatorMode
        {
            Hover,
            HoverButton,
            Aways,
            Never
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -