ivrlistbox.cs

来自「破解的飞信源代码」· CS 代码 · 共 347 行

CS
347
字号
namespace Imps.Client.Pc
{
    using Imps.Client.Utils;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class IVRListBox : ListBox
    {
        private Color _borderColor = Color.FromArgb(0xa4, 170, 220);
        private string _cancelDescription = "取消邀请";
        private Image _cancelImage;
        private Color _disableColor = Color.Silver;
        private int _iVRItemHeight = 80;
        private Font _lnkFont = new Font("Microsoft Sans Serif", 9f, FontStyle.Underline, GraphicsUnit.Point, 0);
        private Color _moodPhraseColor = Color.FromArgb(0xa4, 170, 220);
        private Font _moodPhraseFont = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
        private int _padding = 8;
        private int _seperatorHeight = 1;
        private bool _showOneLine;
        private IContainer components;

        public event EventHandler<IVRListItemEventArgs> IVRCancelClick;

        public event EventHandler<IVRListItemEventArgs> IVRImageClick;

        public event EventHandler<IVRListItemEventArgs> IVRNameClick;

        public IVRListBox()
        {
            this.InitializeComponent();
            base.SetStyle(0x22000, true);
            this.DrawMode = DrawMode.OwnerDrawVariable;
        }

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

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

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            try
            {
                if (!base.DesignMode && (e.Index != -1))
                {
                    Rectangle itemRectangle = base.GetItemRectangle(e.Index);
                    Graphics graphics = e.Graphics;
                    if (base.Items[e.Index] is IVRSeperatorItem)
                    {
                        Rectangle rect = Rectangle.FromLTRB(itemRectangle.Left, itemRectangle.Top, itemRectangle.Right - 20, itemRectangle.Top + 1);
                        using (LinearGradientBrush brush = new LinearGradientBrush(rect, SystemColors.get_ButtonShadow(), Color.White, LinearGradientMode.Horizontal))
                        {
                            e.Graphics.FillRectangle(brush, rect);
                            return;
                        }
                    }
                    itemRectangle.Inflate(-this._padding, -this._padding);
                    IVRListItem item = base.Items[e.Index] as IVRListItem;
                    item.Rect = itemRectangle;
                    if (item.Image != null)
                    {
                        Rectangle rectangle3 = Rectangle.FromLTRB(itemRectangle.Left, itemRectangle.Top, (itemRectangle.Left + this.IVRItemHeight) - (this._padding * 2), itemRectangle.Bottom);
                        if (!this._showOneLine)
                        {
                            rectangle3.Inflate(-10, -10);
                        }
                        item.ImageRec = rectangle3;
                        graphics.DrawImage(new Bitmap(item.Image), rectangle3);
                        using (Pen pen = new Pen(this._borderColor))
                        {
                            graphics.DrawRectangle(pen, new Rectangle(rectangle3.Left - 3, rectangle3.Top - 3, rectangle3.Width + 6, rectangle3.Height + 6));
                        }
                        Rectangle rectangle4 = Rectangle.FromLTRB(itemRectangle.Left + this.IVRItemHeight, itemRectangle.Top + this._padding, itemRectangle.Right - this._padding, itemRectangle.Top + (itemRectangle.Height / 2));
                        SizeF ef = graphics.MeasureString(item.Name, this._lnkFont);
                        Rectangle rectangle5 = new Rectangle(rectangle4.Left, rectangle4.Top, Convert.ToInt32(ef.Width), Convert.ToInt32(ef.Height));
                        if (rectangle4.Height < ef.Height)
                        {
                            rectangle4.Inflate(0, Convert.ToInt32((double) (Math.Floor((double) ef.Height) - rectangle4.Height)));
                        }
                        TextRenderer.DrawText((IDeviceContext) graphics, item.Name, this._lnkFont, rectangle4, item.Disable ? this._disableColor : Color.Blue, 0x8000);
                        item.NameRec = rectangle5;
                        if ((item.MoodePhrase != null) && (item.MoodePhrase != ""))
                        {
                            Rectangle rectangle6 = Rectangle.FromLTRB(rectangle5.Right + 2, rectangle5.Top, itemRectangle.Right, rectangle5.Bottom);
                            TextRenderer.DrawText((IDeviceContext) graphics, "-" + item.MoodePhrase, this._moodPhraseFont, rectangle6, item.Disable ? this._disableColor : this._moodPhraseColor, 0x8000);
                        }
                        if (!this._showOneLine)
                        {
                            rectangle4.Offset(0, rectangle4.Height);
                            TextRenderer.DrawText((IDeviceContext) graphics, item.Description, this.Font, rectangle4, item.Disable ? this._disableColor : item.DescriptColor, 0x8004);
                            item.DescriptionRec = rectangle4;
                            if (item.ShowCancelButton)
                            {
                                SizeF ef2 = graphics.MeasureString(this.CancelDescription, this._lnkFont);
                                Rectangle rectangle7 = Rectangle.FromLTRB((((itemRectangle.Width - Convert.ToInt32(ef2.Width)) - this.CancelImage.Width) - this._padding) - 2, rectangle4.Top, rectangle4.Right, rectangle4.Bottom + 12);
                                item.CancelButtonRec = rectangle7;
                                graphics.DrawImage(this.CancelImage, new Rectangle(rectangle7.Left, rectangle7.Top, (rectangle7.Height * this.CancelImage.Width) / this.CancelImage.Height, rectangle7.Height));
                                TextRenderer.DrawText((IDeviceContext) graphics, this.CancelDescription, this._lnkFont, new Rectangle((rectangle7.Left + this.CancelImage.Width) + 2, rectangle7.Top, Convert.ToInt32(ef2.Width), rectangle7.Height), item.Disable ? this._disableColor : Color.Blue, 0x8004);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        public virtual void OnIVRCancelClick(IVRListItemEventArgs e)
        {
            if (this.IVRCancelClick != null)
            {
                this.IVRCancelClick.Invoke(this, e);
            }
        }

        public virtual void OnIVRImageClick(IVRListItemEventArgs e)
        {
            if (this.IVRImageClick != null)
            {
                this.IVRImageClick.Invoke(this, e);
            }
        }

        public virtual void OnIVRNameClick(IVRListItemEventArgs e)
        {
            if (this.IVRNameClick != null)
            {
                this.IVRNameClick.Invoke(this, e);
            }
        }

        protected override void OnMeasureItem(MeasureItemEventArgs e)
        {
            if (!base.DesignMode)
            {
                if (base.Items[e.Index] is IVRSeperatorItem)
                {
                    e.ItemHeight = this._seperatorHeight;
                }
                else
                {
                    e.ItemHeight = this._iVRItemHeight;
                }
            }
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Left)
                {
                    int num = base.IndexFromPoint(e.get_Location());
                    if (base.Items[num] is IVRListItem)
                    {
                        IVRListItem item = base.Items[num] as IVRListItem;
                        if (item.ImageRec.Contains(e.get_Location()))
                        {
                            this.OnIVRImageClick(new IVRListItemEventArgs(item));
                        }
                        if (item.ShowCancelButton && item.CancelButtonRec.Contains(e.get_Location()))
                        {
                            this.OnIVRCancelClick(new IVRListItemEventArgs(item));
                        }
                        if (item.NameRec.Contains(e.get_Location()))
                        {
                            this.OnIVRNameClick(new IVRListItemEventArgs(item));
                        }
                    }
                }
            }
            catch
            {
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            try
            {
                int num = base.IndexFromPoint(e.get_Location());
                if (base.Items[num] is IVRListItem)
                {
                    IVRListItem item = base.Items[num] as IVRListItem;
                    if ((item.ImageRec.Contains(e.get_Location()) || (item.ShowCancelButton && item.CancelButtonRec.Contains(e.get_Location()))) || item.NameRec.Contains(e.get_Location()))
                    {
                        this.Cursor = Cursors.Hand;
                    }
                    else
                    {
                        this.Cursor = Cursors.Arrow;
                    }
                }
            }
            catch
            {
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            using (Pen pen = new Pen(Color.FromArgb(0xa4, 170, 220), 1f))
            {
                e.Graphics.DrawRectangle(pen, 0, 0, base.Width - 1, base.Height - 1);
            }
        }

        protected Color BorderColor
        {
            get
            {
                return this._borderColor;
            }
            set
            {
                this._borderColor = value;
            }
        }

        public string CancelDescription
        {
            get
            {
                return this._cancelDescription;
            }
            set
            {
                this._cancelDescription = value;
            }
        }

        public Image CancelImage
        {
            get
            {
                return this._cancelImage;
            }
            set
            {
                this._cancelImage = value;
            }
        }

        public Color DisableColor
        {
            get
            {
                return this._disableColor;
            }
            set
            {
                this._disableColor = value;
            }
        }

        public int IVRItemHeight
        {
            get
            {
                return this._iVRItemHeight;
            }
            set
            {
                this._iVRItemHeight = value;
            }
        }

        public Font LnkFont
        {
            get
            {
                return this._lnkFont;
            }
            set
            {
                this._lnkFont = value;
            }
        }

        public Color MoodPhraseColor
        {
            get
            {
                return this._moodPhraseColor;
            }
            set
            {
                this._moodPhraseColor = value;
            }
        }

        public Font MoodPhraseFont
        {
            get
            {
                return this._moodPhraseFont;
            }
            set
            {
                this._moodPhraseFont = value;
            }
        }

        public int SeperatorHeight
        {
            get
            {
                return this._seperatorHeight;
            }
            set
            {
                this._seperatorHeight = value;
            }
        }

        public bool ShowOneLine
        {
            get
            {
                return this._showOneLine;
            }
            set
            {
                this._showOneLine = value;
            }
        }
    }
}

⌨️ 快捷键说明

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