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

📄 elementbutton.cs

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

    public class ElementButton : Element
    {
        protected bool _down;
        public Font _font;
        public Color _font_color = Color.Black;
        private ButtonState _state;
        private string _text;
        public string _tooltip;

        public ElementButton()
        {
            base._style = new ElementButtonStyle();
            base._style.StyleChanged += new EventHandler(this.style_StyleChanged);
            this._tooltip = string.Empty;
        }

        public override void Dispose()
        {
            base._style.StyleChanged -= new EventHandler(this.style_StyleChanged);
            base.Dispose();
        }

        public override void OnMouseDown(MouseEventArgs e)
        {
            if ((e.Button == MouseButtons.Left) && (this.State != ButtonState.STATE_DISABLE))
            {
                this._down = true;
                this.State = ButtonState.STATE_DOWN;
            }
        }

        public override void OnMouseHover(MouseEventArgs e)
        {
            base.OnMouseHover(e);
            if (this.State != ButtonState.STATE_DISABLE)
            {
                if (this._down)
                {
                    this.State = ButtonState.STATE_DOWN;
                }
                else
                {
                    this.State = ButtonState.STATE_HOVER;
                }
            }
        }

        public override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            if (this.State != ButtonState.STATE_DISABLE)
            {
                this.State = ButtonState.STATE_NORMAL;
            }
        }

        public override void OnMouseUp(MouseEventArgs e)
        {
            if ((e.Button == MouseButtons.Left) && (this.State != ButtonState.STATE_DISABLE))
            {
                ButtonState state = this.State;
                this._state = ButtonState.STATE_NORMAL;
                if (state != this._state)
                {
                    base.RaiseInvalidate(true);
                }
                if (this._down && (state == ButtonState.STATE_DOWN))
                {
                    this.OnMouseClick(e);
                }
                this._down = false;
            }
        }

        public override void OnPaint(PaintEventArgs e)
        {
            if (base.Visible)
            {
                try
                {
                    Image image;
                    switch (this._state)
                    {
                        case ButtonState.STATE_NORMAL:
                            image = this.Style._normal_image;
                            break;

                        case ButtonState.STATE_DOWN:
                            image = this.Style._down_image;
                            break;

                        case ButtonState.STATE_HOVER:
                            image = this.Style._hover_image;
                            break;

                        case ButtonState.STATE_DISABLE:
                            image = this.Style._disable_image;
                            break;

                        default:
                            image = null;
                            break;
                    }
                    Graphics graphics = e.Graphics;
                    if (image == null)
                    {
                        image = this.Style._normal_image;
                    }
                    if (image != null)
                    {
                        if (this.Style.TransParentColor != null)
                        {
                            ImageAttributes imageAttr = new ImageAttributes();
                            imageAttr.SetColorKey(this.Style.TransParentColor.Color, this.Style.TransParentColor.Color);
                            graphics.DrawImage(image, new Rectangle(this._location.X, this._location.Y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
                        }
                        else
                        {
                            graphics.DrawImage(image, new Rectangle(this._location.X, this._location.Y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                        }
                    }
                    if (this.Icon != null)
                    {
                        Rectangle rectangle = EStyleBase.GetStretchRectangle(this.Icon.Size, base.Rectangle, this.Style._icon_stretch);
                        Rectangle rect = EStyleBase.GetAlignmentRectangle(new Size(rectangle.Width, rectangle.Height), base.Rectangle, this.Style._icon_hor_alignment, this.Style._icon_ver_alignment);
                        graphics.DrawImage(this.Icon, rect);
                    }
                    if (this.Text != null)
                    {
                        using (StringFormat format = new StringFormat())
                        {
                            switch (this.Style._text_hor_alignment)
                            {
                                case EAlignment.left:
                                    format.Alignment = StringAlignment.Near;
                                    break;

                                case EAlignment.right:
                                    format.Alignment = StringAlignment.Far;
                                    break;

                                default:
                                    format.Alignment = StringAlignment.Center;
                                    break;
                            }
                            switch (this.Style._text_ver_alignment)
                            {
                                case EAlignment.top:
                                    format.LineAlignment = StringAlignment.Near;
                                    break;

                                case EAlignment.bottom:
                                    format.LineAlignment = StringAlignment.Far;
                                    break;

                                default:
                                    format.LineAlignment = StringAlignment.Center;
                                    break;
                            }
                            format.FormatFlags |= StringFormatFlags.NoWrap;
                            format.Trimming = StringTrimming.EllipsisCharacter;
                            Color color = this._font_color;
                            switch (this.State)
                            {
                                case ButtonState.STATE_NORMAL:
                                    color = this.Style._fontNormalColor;
                                    break;

                                case ButtonState.STATE_DOWN:
                                    color = this.Style._fontDownColor;
                                    break;

                                case ButtonState.STATE_HOVER:
                                    color = this.Style._fontHoverColor;
                                    break;

                                case ButtonState.STATE_DISABLE:
                                    color = this.Style._fontDisableColor;
                                    break;
                            }
                            if (color == Color.Empty)
                            {
                                color = this._font_color;
                            }
                            using (Brush brush = new SolidBrush(color))
                            {
                                Rectangle layoutRectangle = new Rectangle(this._location.X + this.Style._fontPaddingLeft, this._location.Y + this.Style._fontPaddingTop, this._size.Width - this.Style._fontPaddingLeft, this._size.Height - this.Style._fontPaddingTop);
                                graphics.DrawString(this.Text, this._font, brush, layoutRectangle, format);
                            }
                        }
                    }
                }
                catch
                {
                }
            }
        }

        public override void OnSizeChanged(int w, int h)
        {
            base._size = this.Style._size;
            base._location = EStyleBase.StyleLocationToWindowLocation(this.Style._location, this.Style._xAlignment, this.Style._yAlignment, new Size(w, h));
        }

        private void style_StyleChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Style._fontFamily))
            {
                this._font = null;
            }
            else
            {
                FontStyle regular = FontStyle.Regular;
                switch (this.Style._fontStyle)
                {
                    case "Bold":
                        regular = FontStyle.Bold;
                        break;

                    case "Italic":
                        regular = FontStyle.Italic;
                        break;

                    case "Regular":
                        regular = FontStyle.Regular;
                        break;

                    case "Underline":
                        regular = FontStyle.Underline;
                        break;
                }
                try
                {
                    this._font = new Font(this.Style._fontFamily, (float) this.Style._fontSize, regular);
                    if (!string.IsNullOrEmpty(this.Style._string))
                    {
                        this.Text = this.Style._string;
                    }
                }
                catch
                {
                    this._font = null;
                    this.Text = null;
                }
            }
        }

        public Image Icon
        {
            get
            {
                return this.Style._icon;
            }
            set
            {
                this.Style._icon = value;
            }
        }

        public ButtonState State
        {
            get
            {
                return this._state;
            }
            set
            {
                ButtonState state = this._state;
                this._state = value;
                if (state != this._state)
                {
                    base.RaiseInvalidate(false);
                }
            }
        }

        public ElementButtonStyle Style
        {
            get
            {
                return (ElementButtonStyle) base._style;
            }
        }

        public string Text
        {
            get
            {
                return this._text;
            }
            set
            {
                this._text = value;
            }
        }

        public enum ButtonState
        {
            STATE_NORMAL,
            STATE_DOWN,
            STATE_HOVER,
            STATE_DISABLE
        }
    }
}

⌨️ 快捷键说明

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