📄 sendmessagebutton.cs
字号:
namespace Imps.Client.Pc.BizControls.Conversation
{
using Imps.Client.Pc;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public class SendMessageButton : Control
{
private int arrowBoundWidth = 0x13;
private Color borderColor = Color.FromArgb(0xf7, 0xb2, 0x53);
protected Rectangle buttonBounds;
private bool disabled;
private Color disabledBackgroudColor = Color.White;
private Image disabledBackgroundImage;
private Color disabledBorderColor = Color.Gray;
private Image disabledDropDownButtonImage;
private Color disabledForeColor = Color.Gray;
protected Rectangle dropDownButtonBounds;
private Image dropDownButtonImage;
private ContextMenuStrip dropDownMenu;
protected StringFormat format;
private bool isMenuPopup;
private Status status;
protected Rectangle textBounds;
private ToolTip textToolTip;
private string toolTipText = "";
public event EventHandler ButtonClick;
public SendMessageButton()
{
base.Size = new Size(0x54, 0x1a);
this.format = new StringFormat();
this.format.Alignment = StringAlignment.Center;
this.format.LineAlignment = StringAlignment.Center;
this.format.HotkeyPrefix = HotkeyPrefix.Show;
this.Font = new Font(this.Font, FontStyle.Bold);
this.textToolTip = new ToolTip();
MiscStyle.Instance.StyleChanged += new EventHandler(this.Instance_StyleChanged);
}
public void AdjustSize()
{
this.textBounds = base.ClientRectangle;
}
protected override void Dispose(bool disposing)
{
MiscStyle.Instance.StyleChanged -= new EventHandler(this.Instance_StyleChanged);
if (disposing && (this.textToolTip != null))
{
this.textToolTip.Dispose();
this.textToolTip = null;
}
base.Dispose(disposing);
}
private void DropDownMenuVisibleChanged(object sender, EventArgs e)
{
this.isMenuPopup = this.DropDownMenu.get_Visible();
base.Invalidate();
}
private void Instance_StyleChanged(object sender, EventArgs e)
{
base.Invalidate();
}
public void OnButtonClick(EventArgs e)
{
if (this.ButtonClick != null)
{
this.ButtonClick(this, e);
}
}
protected override void OnCreateControl()
{
base.OnCreateControl();
this.textToolTip.SetToolTip(this, this.ToolTipText);
}
protected override void OnMouseClick(MouseEventArgs e)
{
if ((e.Button == MouseButtons.Left) && !this.Disabled)
{
this.OnButtonClick(new EventArgs());
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.status = Status.Down;
base.Invalidate();
base.OnMouseDown(e);
}
protected override void OnMouseEnter(EventArgs e)
{
this.status = Status.Hover;
base.Invalidate();
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
this.status = Status.Normal;
base.Invalidate();
base.OnMouseLeave(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
this.status = Status.Hover;
base.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
this.AdjustSize();
string text = this.Text;
if (this.Disabled)
{
DrawHelper.DrawStringDisabled(g, this.Text, this.textBounds, this.Font, this.format.Alignment, this.ForeColor);
}
else
{
Rectangle layoutRectangle = this.textBounds;
if (this.status == Status.Down)
{
layoutRectangle.Offset(1, 1);
}
g.DrawString(this.Text, this.Font, Brushes.White, layoutRectangle, this.format);
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Rectangle clipRectangle = e.ClipRectangle;
Graphics graphics = e.Graphics;
Rectangle rect = new Rectangle(0, 0, base.Width, base.Height);
using (Brush brush = new SolidBrush(Color.Gray))
{
graphics.FillRectangle(brush, rect);
ImageAttributes imageAttr = new ImageAttributes();
if (this.Disabled)
{
Image sendButtonBgDisable = MiscStyle.Instance.SendButtonBgDisable;
if (sendButtonBgDisable == null)
{
sendButtonBgDisable = this.DisabledBackgroundImage;
}
if (sendButtonBgDisable != null)
{
graphics.DrawImage(sendButtonBgDisable, rect, 0, 0, sendButtonBgDisable.Width, sendButtonBgDisable.Height, GraphicsUnit.Pixel, imageAttr);
}
if (!this.isMenuPopup && (this.status != Status.Normal))
{
}
}
else
{
Image image = null;
switch (this.status)
{
case Status.Normal:
image = MiscStyle.Instance.SendButtonBgNormal;
break;
case Status.Hover:
image = MiscStyle.Instance.SendButtonBgHover;
break;
case Status.Down:
image = MiscStyle.Instance.SendButtonBgDown;
break;
}
if (image == null)
{
image = this.BackgroundImage;
}
if (image != null)
{
graphics.DrawImage(image, rect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
}
if (!this.isMenuPopup)
{
Status status = this.status;
}
}
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
base.Invalidate();
}
private void PaintBackColor(PaintEventArgs e, Rectangle rectangle, Color backColor)
{
Color color = backColor;
if (color.A > 0)
{
using (Brush brush = new SolidBrush(color))
{
e.Graphics.FillRectangle(brush, rectangle);
}
}
}
public Color BorderColor
{
get
{
return this.borderColor;
}
set
{
this.borderColor = value;
}
}
public bool Disabled
{
get
{
return this.disabled;
}
set
{
if (this.disabled != value)
{
this.disabled = value;
base.Invalidate();
}
}
}
public Color DisabledBackgroudColor
{
get
{
return this.disabledBackgroudColor;
}
set
{
this.disabledBackgroudColor = value;
}
}
public Image DisabledBackgroundImage
{
get
{
if (this.disabledBackgroundImage == null)
{
return this.BackgroundImage;
}
return this.disabledBackgroundImage;
}
set
{
this.disabledBackgroundImage = value;
}
}
public Color DisabledBorderColor
{
get
{
return this.disabledBorderColor;
}
set
{
this.disabledBorderColor = value;
}
}
public Image DisabledDropDownButtonImage
{
get
{
if (this.disabledDropDownButtonImage == null)
{
return this.DropDownButtonImage;
}
return this.disabledDropDownButtonImage;
}
set
{
this.disabledDropDownButtonImage = value;
}
}
public Color DisabledForeColor
{
get
{
return this.disabledForeColor;
}
set
{
this.disabledForeColor = value;
}
}
public Image DropDownButtonImage
{
get
{
return this.dropDownButtonImage;
}
set
{
this.dropDownButtonImage = value;
}
}
public ContextMenuStrip DropDownMenu
{
get
{
return this.dropDownMenu;
}
set
{
if (this.dropDownMenu != null)
{
this.dropDownMenu.VisibleChanged -= new EventHandler(this.DropDownMenuVisibleChanged);
}
this.dropDownMenu = value;
if (this.dropDownMenu != null)
{
this.dropDownMenu.VisibleChanged += new EventHandler(this.DropDownMenuVisibleChanged);
}
}
}
public string ToolTipText
{
get
{
return this.toolTipText;
}
set
{
this.toolTipText = value;
}
}
public enum Status
{
Normal,
Hover,
Down
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -