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

📄 ivrlistbox.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc
{
    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(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, 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)
        {
            if (!base.DesignMode)
            {
                Rectangle itemRectangle = base.GetItemRectangle(e.Index);
                Graphics dc = 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.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;
                    dc.DrawImage(new Bitmap(item.Image), rectangle3);
                    using (Pen pen = new Pen(this._borderColor))
                    {
                        dc.DrawRectangle(pen, new Rectangle(rectangle3.Left - 3, rectangle3.Top - 3, rectangle3.Width + 6, rectangle3.Height + 6));
                    }
                    Rectangle bounds = Rectangle.FromLTRB(itemRectangle.Left + this.IVRItemHeight, itemRectangle.Top + this._padding, itemRectangle.Right - this._padding, itemRectangle.Top + (itemRectangle.Height / 2));
                    SizeF ef = dc.MeasureString(item.Name, this._lnkFont);
                    Rectangle rectangle5 = new Rectangle(bounds.Left, bounds.Top, Convert.ToInt32(ef.Width), Convert.ToInt32(ef.Height));
                    if (bounds.Height < ef.Height)
                    {
                        bounds.Inflate(0, Convert.ToInt32((double) (Math.Floor((double) ef.Height) - bounds.Height)));
                    }
                    TextRenderer.DrawText(dc, item.Name, this._lnkFont, bounds, item.Disable ? this._disableColor : Color.Blue, TextFormatFlags.EndEllipsis);
                    item.NameRec = rectangle5;
                    if ((item.MoodePhrase != null) && (item.MoodePhrase != ""))
                    {
                        Rectangle rectangle6 = Rectangle.FromLTRB(rectangle5.Right + 2, rectangle5.Top, itemRectangle.Right, rectangle5.Bottom);
                        TextRenderer.DrawText(dc, "-" + item.MoodePhrase, this._moodPhraseFont, rectangle6, item.Disable ? this._disableColor : this._moodPhraseColor, TextFormatFlags.EndEllipsis);
                    }
                    if (!this._showOneLine)
                    {
                        bounds.Offset(0, bounds.Height);
                        TextRenderer.DrawText(dc, item.Description, this.Font, bounds, item.Disable ? this._disableColor : item.DescriptColor, TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter);
                        item.DescriptionRec = bounds;
                        if (item.ShowCancelButton)
                        {
                            SizeF ef2 = dc.MeasureString(this.CancelDescription, this._lnkFont);
                            Rectangle rectangle7 = Rectangle.FromLTRB((((itemRectangle.Width - Convert.ToInt32(ef2.Width)) - this.CancelImage.Width) - this._padding) - 2, bounds.Top, bounds.Right, bounds.Bottom);
                            item.CancelButtonRec = rectangle7;
                            dc.DrawImage(this.CancelImage, new Rectangle(rectangle7.Left, rectangle7.Top, this.CancelImage.Width, rectangle7.Height));
                            TextRenderer.DrawText(dc, 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, TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter);
                        }
                    }
                }
            }
        }

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

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

        public virtual void OnIVRNameClick(IVRListItemEventArgs e)
        {
            if (this.IVRNameClick != null)
            {
                this.IVRNameClick(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.Location);
                    if (base.Items[num] is IVRListItem)
                    {
                        IVRListItem item = base.Items[num] as IVRListItem;
                        if (item.ImageRec.Contains(e.Location))
                        {
                            this.OnIVRImageClick(new IVRListItemEventArgs(item));
                        }
                        if (item.ShowCancelButton && item.CancelButtonRec.Contains(e.Location))
                        {
                            this.OnIVRCancelClick(new IVRListItemEventArgs(item));
                        }
                        if (item.NameRec.Contains(e.Location))
                        {
                            this.OnIVRNameClick(new IVRListItemEventArgs(item));
                        }
                    }
                }
            }
            catch
            {
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            try
            {
                int num = base.IndexFromPoint(e.Location);
                if (base.Items[num] is IVRListItem)
                {
                    IVRListItem item = base.Items[num] as IVRListItem;
                    if ((item.ImageRec.Contains(e.Location) || (item.ShowCancelButton && item.CancelButtonRec.Contains(e.Location))) || item.NameRec.Contains(e.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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -