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

📄 bdisplaypersonalmessage.cs

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

    public class BDisplayPersonalMessage : BDropdownControl
    {
        private string cachedText = "";
        private string dropdownButtonTootipText = "选择此选项显示您的历史心情短语";
        private string emptyPersonalMessageText = "<请输入心情短语>";
        private Color emptyPersonalMessageTextForeColor = Color.Silver;
        private System.Drawing.Font font = new System.Drawing.Font("Arial", 9f);
        private StringFormat format;
        private bool inDropdownButton;
        private bool isEditing;
        private rich_string m_personal_message = new rich_string();
        private ChatEditCtrlManager m_txtPersonalMessageMgr;
        private int personalMessagePaddingLeft = 1;
        private int personalMessagePaddingRight = 1;
        private Size personalMessageSize;
        private Rectangle rectPersonalMessage;
        private Rectangle rectTextbox;
        private Color textboxBorderColor = Color.FromArgb(0x98, 0x97, 0x8b);
        private ChatRichTextBox txtPersonalMessage;

        public event EventHandler TextBoxAccepted;

        public BDisplayPersonalMessage()
        {
            base.toolTipText = "单击此处键入您的心情短语";
            this.format = new StringFormat();
            this.format.LineAlignment = StringAlignment.Center;
            this.format.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.FitBlackBox;
            this.format.Trimming = StringTrimming.EllipsisCharacter;
            this.InitTextbox();
        }

        protected override void AdjustTextSize(Graphics g)
        {
            if (base.totalWidth > this.preferredSize.Width)
            {
                base.totalWidth = this.preferredSize.Width;
                this.personalMessageSize.Width = (((this.preferredSize.Width - base.dropDownButtonWidth) - 4) - this.personalMessagePaddingLeft) - this.personalMessagePaddingRight;
            }
            if (this.personalMessageSize.Width < 0)
            {
                this.personalMessageSize.Width = 0;
            }
            this.rectPersonalMessage = new Rectangle(this.personalMessagePaddingLeft, (base.Height - this.personalMessageSize.Height) / 2, this.personalMessageSize.Width + this.personalMessagePaddingRight, this.personalMessageSize.Height);
            this.rectTextbox = new Rectangle(0, 0, ((base.totalWidth - base.dropDownButtonWidth) - 4) - 1, base.Height - 1);
            this.txtPersonalMessage.SetBounds(this.rectTextbox.X + 2, this.rectTextbox.Y + 2, this.rectTextbox.Width - 2, this.rectTextbox.Height - 3);
        }

        private void BeginEdit()
        {
            if (!this.isEditing)
            {
                this.isEditing = true;
                this.txtPersonalMessage.Text = string.Empty;
                this.m_txtPersonalMessageMgr.AddRichTextString(this.Text);
                this.txtPersonalMessage.ClearUndo();
                this.txtPersonalMessage.Visible = true;
                this.txtPersonalMessage.Focus();
                this.txtPersonalMessage.SelectAll();
                this.cachedText = this.Text;
            }
        }

        private void CancelEdit()
        {
            if (this.isEditing)
            {
                this.isEditing = false;
                this.txtPersonalMessage.Visible = false;
                this.Text = this.cachedText;
            }
        }

        private void EditBackground(Graphics g)
        {
            using (Brush brush = new SolidBrush(base.BackColor))
            {
                g.FillRectangle(brush, base.rectText);
                using (Pen pen = new Pen(this.TextboxBorderColor))
                {
                    g.DrawRectangle(pen, base.rectText);
                }
            }
        }

        private void EndEdit()
        {
            if (this.isEditing)
            {
                this.isEditing = false;
                this.Text = this.m_txtPersonalMessageMgr.Text;
                this.txtPersonalMessage.Visible = false;
                this.OnTextBoxAccepted(new EventArgs());
                this.cachedText = this.Text;
            }
        }

        private void HoverDropdownButton(Graphics g)
        {
            using (Pen pen = new Pen(base.MouseOverBorderColor))
            {
                if (base.mouseStatus == MouseStatus.Down)
                {
                    pen.Color = base.MouseDownBorderColor;
                }
                g.DrawLine(pen, this.rectDropDownButton.Left - 2, 1, this.rectDropDownButton.Left - 2, base.Height - 2);
                pen.Color = base.BackColor;
                g.DrawLine(pen, this.rectDropDownButton.Left - 1, 1, this.rectDropDownButton.Left - 1, base.Height - 2);
            }
        }

        private void InitTextbox()
        {
            this.txtPersonalMessage = new ChatRichTextBox();
            this.txtPersonalMessage.Font = this.font;
            this.txtPersonalMessage.SelectionFont = this.font;
            this.txtPersonalMessage.Height = base.Height - 2;
            this.txtPersonalMessage.Visible = false;
            this.txtPersonalMessage.BorderStyle = BorderStyle.None;
            this.txtPersonalMessage.Multiline = false;
            this.txtPersonalMessage.SelectionIndent = 1;
            this.txtPersonalMessage.SelectionRightIndent = 1;
            this.txtPersonalMessage.ShowSelectionMargin = false;
            this.txtPersonalMessage.BackColor = Color.White;
            this.txtPersonalMessage.DetectUrls = false;
            this.txtPersonalMessage.KeyDown += new KeyEventHandler(this.txtPersonalMessage_KeyDown);
            this.txtPersonalMessage.LostFocus += new EventHandler(this.txtPersonalMessage_LostFocus);
            base.Controls.Add(this.txtPersonalMessage);
            this.m_txtPersonalMessageMgr = new ChatEditCtrlManager(this.txtPersonalMessage, false);
            this.m_txtPersonalMessageMgr.DefaultTextFont = SystemFonts.get_DefaultFont();
            this.m_txtPersonalMessageMgr.ConvertString = new DelegateConvert(StringHelper.EncodString);
            if (EnvHelper.DynamicGifCtlRegistered)
            {
                this.m_txtPersonalMessageMgr.ConvertSympol = true;
            }
            this.m_txtPersonalMessageMgr.SympolSize = new Size(0x10, 0x10);
        }

        protected override int MeasureTextWidth(Graphics g)
        {
            if (!string.IsNullOrEmpty(this.m_personal_message.plane_text))
            {
                this.personalMessageSize = this.m_personal_message.MeasureText(g, this.Font, this.format).ToSize();
            }
            else
            {
                this.personalMessageSize = g.MeasureString(this.DrawText, this.Font, (PointF) Point.Empty, this.format).ToSize();
            }
            return ((this.personalMessageSize.Width + this.personalMessagePaddingLeft) + this.personalMessagePaddingRight);
        }

        protected override void OnCreateControl()
        {
            this.txtPersonalMessage.Font = this.font;
            this.txtPersonalMessage.SelectionFont = this.font;
            base.Font = this.font;
            base.OnCreateControl();
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.KeyCode == Keys.Return)
            {
                this.EndEdit();
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.CancelEdit();
            }
            base.Invalidate();
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (this.rectDropDownButton.Contains(e.X, e.Y))
                {
                    if (base.DropDownMenu != null)
                    {
                        base.DropDownMenu.Show(this, new Point(0, base.Height), 3);
                    }
                    this.EndEdit();
                }
                else if (!this.isEditing && this.rectTextbox.Contains(e.X, e.Y))
                {
                    this.BeginEdit();
                }
                else if (this.isEditing && !this.rectTextbox.Contains(e.X, e.Y))
                {
                    this.EndEdit();
                }
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (this.rectDropDownButton.Contains(e.X, e.Y))
            {
                if (!this.inDropdownButton)
                {
                    base.TextToolTip.SetToolTip(this, this.DropdownButtonTootipText);
                    this.inDropdownButton = true;
                    this.Refresh();
                }
            }
            else if (this.inDropdownButton)
            {
                base.TextToolTip.SetToolTip(this, base.ToolTipText);
                this.inDropdownButton = false;
                this.Refresh();
            }
        }

        public void OnTextBoxAccepted(EventArgs e)
        {
            if (this.TextBoxAccepted != null)
            {
                this.TextBoxAccepted(this, e);
            }
        }

        protected override void PaintBackground(Graphics g)
        {
            if (this.isEditing)
            {
                this.EditBackground(g);
            }
        }

        protected override void PaintMouseDownBackground(Graphics g)
        {
            base.PaintMouseDownBackground(g);
            if (this.isEditing)
            {
                this.EditBackground(g);
            }
            if (this.inDropdownButton)
            {
                this.HoverDropdownButton(g);
            }
        }

        protected override void PaintMouseHoverBackground(Graphics g)
        {
            if (base.isMenuPopup)
            {
                base.PaintMouseHoverBackground(g);
            }
            else
            {
                base.PaintMouseHoverBackground(g);
                if (this.isEditing)
                {
                    using (Brush brush = new SolidBrush(base.BackColor))
                    {
                        g.FillRectangle(brush, base.rectText);
                        using (Pen pen = new Pen(this.TextboxBorderColor))
                        {
                            g.DrawRectangle(pen, base.rectText);
                        }
                    }
                }
                if (this.inDropdownButton)
                {
                    this.HoverDropdownButton(g);
                }
            }
        }

        protected override void PaintText(Graphics g)
        {
            if (!this.isEditing)
            {
                if (this.IsEmptyText)
                {
                    using (Brush brush = new SolidBrush(this.EmptyPersonalMessageTextForeColor))
                    {
                        g.DrawString(this.DrawText, this.Font, brush, this.rectPersonalMessage, this.format);
                        return;
                    }
                }
                this.m_personal_message.Draw(g, this.Font, this.ForeColor, this.rectPersonalMessage, this.format);
            }
        }

        private void txtPersonalMessage_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                this.EndEdit();
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.CancelEdit();
            }
        }

        private void txtPersonalMessage_LostFocus(object sender, EventArgs e)
        {
            this.EndEdit();
        }

        private void txtPersonalMessage_TextChanged(object sender, EventArgs e)
        {
            this.Text = this.m_txtPersonalMessageMgr.Text;
        }

        public string DrawText
        {
            get
            {
                if (this.IsEmptyText)
                {
                    return this.EmptyPersonalMessageText;
                }
                return this.PersonalMessageText;
            }
        }

        public string DropdownButtonTootipText
        {
            get
            {
                return this.dropdownButtonTootipText;
            }
            set
            {
                this.dropdownButtonTootipText = value;
            }
        }

        public string EmptyPersonalMessageText
        {
            get
            {
                return this.emptyPersonalMessageText;
            }
            set
            {
                this.emptyPersonalMessageText = value;
            }
        }

        public Color EmptyPersonalMessageTextForeColor
        {
            get
            {
                return this.emptyPersonalMessageTextForeColor;
            }
            set
            {
                this.emptyPersonalMessageTextForeColor = value;
            }
        }

        public System.Drawing.Font Font
        {
            get
            {
                return this.font;
            }
            set
            {
                this.font = value;
            }
        }

        public bool IsEmptyText
        {
            get
            {
                return string.IsNullOrEmpty(this.PersonalMessageText);
            }
        }

        public int MaxLength
        {
            get
            {
                return this.txtPersonalMessage.MaxLength;
            }
            set
            {
                this.txtPersonalMessage.MaxLength = value;
            }
        }

        public string PersonalMessageText
        {
            get
            {
                return this.m_personal_message.plane_text;
            }
            set
            {
                this.m_personal_message.plane_text = (value == null) ? string.Empty : value.Replace("\n", string.Empty);
                base.Invalidate();
            }
        }

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

        public Color TextboxBorderColor
        {
            get
            {
                return this.textboxBorderColor;
            }
            set
            {
                this.textboxBorderColor = value;
            }
        }
    }
}

⌨️ 快捷键说明

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