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

📄 ximagelistbutton.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Imps.Client.Pc.XControl
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Design;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class XImageListButton : Control
    {
        private Image _imageBackground;
        private readonly ImageCollection _imageCollection;
        private System.Drawing.Size _imageSize;
        private bool _needScroll;
        private int _offset;
        private Image _selectedImageBackground;
        private int _selectIndex;
        private int _splitWidth;
        private const int BUTTON_WIDTH = 20;
        private IContainer components;

        public event EventHandler SelectedChanged;

        public XImageListButton()
        {
            base.SetStyle(0x20812, true);
            this._imageCollection = new ImageCollection(this);
            this.InitializeComponent();
            this._splitWidth = 4;
            this._imageSize = new System.Drawing.Size(0x20, 0x20);
            this._selectIndex = -1;
            this._offset = 0;
        }

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

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.ResumeLayout(false);
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            Point location = e.get_Location();
            this.ParseOperation(location);
            base.OnMouseClick(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            e.get_Location();
            base.OnMouseMove(e);
        }

        private void OnMoveLeft()
        {
            int num = ((this.ImageSize.Width + 14) + this._splitWidth) * this.Items.Count;
            int width = this.ImageRect.Width;
            this._offset -= (this.ImageSize.Width + 14) + this._splitWidth;
            if ((num + this._offset) < width)
            {
                this._offset = width - num;
            }
        }

        private void OnMoveRight()
        {
            this._offset += (this.ImageSize.Width + 14) + this._splitWidth;
            if (this._offset > 0)
            {
                this._offset = 0;
            }
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics g = pe.Graphics;
            this.PaintButton(g);
            this.PaintItems(g);
        }

        private void PaintButton(Graphics g)
        {
            int num = ((this.ImageSize.Width + 14) + this._splitWidth) * this.Items.Count;
            if (num > this.Size.Width)
            {
                Point[] points = new Point[] { new Point(2, base.Height / 2), new Point(0x12, 3), new Point(0x12, base.Height - 3) };
                g.FillPolygon(Brushes.Black, points);
                points[0] = new Point(base.Width - 2, base.Height / 2);
                points[1] = new Point(base.Width - 0x12, 3);
                points[2] = new Point(base.Width - 0x12, base.Height - 3);
                g.FillPolygon(Brushes.Black, points);
                this._needScroll = true;
            }
            else
            {
                this._needScroll = false;
            }
        }

        private void PaintItems(Graphics g)
        {
            g.Clip = new Region(this.ImageRect);
            int num = this._offset;
            if (this._needScroll)
            {
                num += 20;
            }
            else
            {
                this._offset = (this.Size.Width - (((this.ImageSize.Width + 14) + this._splitWidth) * this.Items.Count)) / 2;
                num = this._offset;
            }
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            for (int i = 0; i < this.Items.Count; i++)
            {
                int x = ((num + (((this.ImageSize.Width + 14) + this._splitWidth) * i)) + ((this._splitWidth + 14) / 2)) - 7;
                int y = 2;
                int width = this.ImageSize.Width + 14;
                int height = this.ImageSize.Height + 14;
                if ((i == this.SelectedIndex) && (this._selectedImageBackground != null))
                {
                    g.DrawImage(this._selectedImageBackground, x, y, width, height);
                }
                else if (this._imageBackground != null)
                {
                    g.DrawImage(this._imageBackground, x, y, width, height);
                }
                if (!string.IsNullOrEmpty(this._imageCollection[i].Key))
                {
                    Rectangle layoutRectangle = new Rectangle(x, (y + height) + 2, width, (this.Size.Height - this.ImageSize.Height) - 20);
                    g.DrawString(this._imageCollection[i].Key, this.Font, Brushes.Black, layoutRectangle, format);
                }
                if (this._imageCollection[i].Image != null)
                {
                    g.DrawImage(this._imageCollection[i].Image, (int) (x + 7), (int) (y + 7), (int) (width - 14), (int) (height - 14));
                }
            }
        }

        private void ParseOperation(Point location)
        {
            bool flag = false;
            if (this._needScroll)
            {
                Rectangle rectangle = new Rectangle(0, 0, 20, this.Size.Height);
                if (rectangle.Contains(location))
                {
                    this.OnMoveRight();
                    flag = true;
                }
                rectangle = new Rectangle(base.Width - 20, 0, 20, this.Size.Height);
                if (rectangle.Contains(location))
                {
                    this.OnMoveLeft();
                    flag = true;
                }
            }
            if (!flag)
            {
                int num = (location.X - this.ImageRect.Left) - this._offset;
                int num2 = (num + (this._splitWidth / 2)) / ((this.ImageSize.Width + 14) + this._splitWidth);
                if (num2 >= this.Items.Count)
                {
                    return;
                }
                if (num2 != this._selectIndex)
                {
                    this.SelectedIndex = num2;
                    if (this.SelectedChanged != null)
                    {
                        this.SelectedChanged(this, null);
                    }
                }
            }
            this.Refresh();
        }

        public Image ImageBackground
        {
            get
            {
                return this._imageBackground;
            }
            set
            {
                this._imageBackground = value;
            }
        }

        private Rectangle ImageRect
        {
            get
            {
                if (this._needScroll)
                {
                    return new Rectangle(20, 0, (this.Size.Width - 40) - (this._splitWidth / 2), this.Size.Height);
                }
                return new Rectangle(0, 0, this.Size.Width, this.Size.Height);
            }
        }

        public System.Drawing.Size ImageSize
        {
            get
            {
                return this._imageSize;
            }
            private set
            {
                this._imageSize = value;
                this.Size = new System.Drawing.Size(this.Size.Width, this.ImageSize.Height);
            }
        }

        [DefaultValue((string) null), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MergableProperty(false)]
        public ImageCollection Items
        {
            get
            {
                return this._imageCollection;
            }
        }

        public Image SelectedImageBackground

⌨️ 快捷键说明

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