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

📄 imagebutton_widget.cs

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

    public class imagebutton_widget : UserControl
    {
        private IContainer components;
        private button_state_type m_buttonstate;
        private bool m_mouseover;
        private Image m_state_image;
        private bool m_toggling;
        private ToolTip m_tooltip = new ToolTip();

        public imagebutton_widget()
        {
            this.InitializeComponent();
            this.m_tooltip.ShowAlways = true;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void do_paint()
        {
            try
            {
                if ((!base.IsDisposed && base.IsHandleCreated) && ((base.ClientRectangle.Width > 0) && (base.ClientRectangle.Height > 0)))
                {
                    using (Graphics g = Graphics.FromHwndInternal(base.Handle))
                    {
                        this.do_paint(g);
                    }
                }
            }
            catch
            {
            }
        }

        private void do_paint(Graphics g)
        {
            if ((this.m_state_image != null) && ((base.ClientRectangle.Width != 0) && (base.ClientRectangle.Height != 0)))
            {
                Rectangle destRect = Rectangle.FromLTRB(0, 0, base.ClientRectangle.Width, base.ClientRectangle.Height);
                using (Bitmap image = new Bitmap(destRect.Width, destRect.Height))
                {
                    using (Graphics graphics = Graphics.FromImage(image))
                    {
                        switch (this.m_buttonstate)
                        {
                            case button_state_type.normal:
                                graphics.DrawImage(this.m_state_image, destRect, 0, 0, this.m_state_image.Width / 4, this.m_state_image.Height, GraphicsUnit.Pixel);
                                break;

                            case button_state_type.up:
                                graphics.DrawImage(this.m_state_image, destRect, this.m_state_image.Width / 4, 0, this.m_state_image.Width / 4, this.m_state_image.Height, GraphicsUnit.Pixel);
                                break;

                            case button_state_type.down:
                                graphics.DrawImage(this.m_state_image, destRect, this.m_state_image.Width / 2, 0, this.m_state_image.Width / 4, this.m_state_image.Height, GraphicsUnit.Pixel);
                                break;

                            case button_state_type.disable:
                                graphics.DrawImage(this.m_state_image, destRect, (this.m_state_image.Width * 3) / 4, 0, this.m_state_image.Width / 4, this.m_state_image.Height, GraphicsUnit.Pixel);
                                break;
                        }
                        if (base.DesignMode)
                        {
                            using (Pen pen = new Pen(Color.BlueViolet))
                            {
                                g.DrawRectangle(pen, destRect);
                            }
                        }
                    }
                    g.DrawImage(image, base.ClientRectangle.Location);
                }
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            base.set_AutoScaleMode(1);
        }

        protected override void OnEnabledChanged(EventArgs e)
        {
            base.OnEnabledChanged(e);
            this.m_buttonstate = base.Enabled ? button_state_type.normal : button_state_type.disable;
            this.do_paint();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (base.Enabled)
            {
                this.m_toggling = true;
                this.m_buttonstate = button_state_type.down;
                this.do_paint();
            }
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            this.m_tooltip.Active = false;
            if (base.Enabled)
            {
                this.m_mouseover = false;
                this.m_buttonstate = button_state_type.normal;
                this.do_paint();
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (this.m_mouseover)
            {
                if (!base.ClientRectangle.Contains(e.get_Location()))
                {
                    this.m_tooltip.Active = false;
                    if (base.Enabled)
                    {
                        this.m_mouseover = false;
                        this.m_buttonstate = button_state_type.normal;
                        this.do_paint();
                    }
                }
            }
            else if (base.ClientRectangle.Contains(e.get_Location()))
            {
                this.m_tooltip.Active = true;
                if (base.Enabled)
                {
                    this.m_mouseover = true;
                    this.m_buttonstate = this.m_toggling ? button_state_type.down : button_state_type.up;
                    this.do_paint();
                }
            }
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (base.Enabled)
            {
                this.m_toggling = false;
                if (base.ClientRectangle.Contains(e.get_Location()))
                {
                    this.m_buttonstate = button_state_type.up;
                }
                else
                {
                    this.m_buttonstate = button_state_type.normal;
                }
                this.do_paint();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.m_state_image == null)
            {
                base.OnPaint(e);
            }
            else
            {
                this.do_paint(e.Graphics);
            }
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (this.m_state_image == null)
            {
                base.OnPaintBackground(e);
            }
            else
            {
                this.do_paint(e.Graphics);
            }
        }

        public string prompt
        {
            get
            {
                return this.m_tooltip.GetToolTip(this);
            }
            set
            {
                if (value != null)
                {
                    this.m_tooltip.SetToolTip(this, value);
                }
            }
        }

        public Image state_image
        {
            get
            {
                return this.m_state_image;
            }
            set
            {
                this.m_state_image = value;
                if (this.m_state_image != null)
                {
                    base.Size = new Size(this.m_state_image.Width / 4, this.m_state_image.Height);
                }
                IntPtr handle = base.Handle;
                this.do_paint();
            }
        }

        private enum button_state_type
        {
            disable = 4,
            down = 2,
            normal = 0,
            up = 1
        }
    }
}

⌨️ 快捷键说明

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