📄 bdropdowncontrol.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using Imps.Client.Pc;
using System;
using System.Drawing;
using System.Windows.Forms;
public abstract class BDropdownControl : BControl
{
protected Color backColor = Color.White;
protected Image dropDownButtonImage;
protected int dropDownButtonPadding = 2;
protected int dropDownButtonWidth;
protected ContextMenuStrip dropDownMenu;
protected bool isMenuPopup;
protected Color mouseDownBackColor = Color.White;
protected Image mouseDownBackgroundImage;
protected Color mouseDownBorderColor = Color.FromArgb(0x98, 200, 0xe8);
protected Color mouseOverBackColor = Color.White;
protected Image mouseOverBackgroundImage;
protected Color mouseOverBorderColor = Color.FromArgb(0x48, 0x90, 200);
protected MouseStatus mouseStatus;
protected Size preferredSize;
protected Rectangle rectBackgroundImage;
protected Rectangle rectBorder;
protected Rectangle rectDropDownButton;
protected Rectangle rectDropDownButtonImage;
protected Rectangle rectText;
protected int totalWidth;
public BDropdownControl()
{
base.SetStyle(0x20812, true);
base.BackColor = Color.Transparent;
}
protected virtual void AdjustSize(Graphics g)
{
this.preferredSize = base.Size;
this.dropDownButtonWidth = 0;
int num = this.MeasureTextWidth(g);
this.totalWidth = 4;
this.totalWidth += num;
if (this.dropDownButtonImage != null)
{
this.dropDownButtonWidth = this.dropDownButtonImage.Width + (2 * this.dropDownButtonPadding);
this.totalWidth += this.dropDownButtonWidth;
}
this.AdjustTextSize(g);
this.rectBorder = new Rectangle(0, 0, this.totalWidth - 1, base.Height - 1);
this.rectDropDownButton = new Rectangle((this.totalWidth - this.dropDownButtonWidth) - 2, 0, this.dropDownButtonWidth - 1, base.Height - 1);
this.rectBackgroundImage = new Rectangle(1, 1, this.totalWidth - 2, base.Height - 2);
this.rectText = new Rectangle(0, 0, ((this.totalWidth - this.dropDownButtonWidth) - 4) - 1, base.Height - 1);
if (this.dropDownButtonImage != null)
{
this.rectDropDownButtonImage = new Rectangle(((this.totalWidth - this.dropDownButtonWidth) + this.dropDownButtonPadding) - 2, (base.Height - this.dropDownButtonImage.Height) / 2, this.dropDownButtonImage.Width, this.dropDownButtonImage.Height);
}
}
protected abstract void AdjustTextSize(Graphics g);
private void DropDownMenuVisibleChanged(object sender, EventArgs e)
{
this.isMenuPopup = this.DropDownMenu.get_Visible();
base.Invalidate();
}
protected abstract int MeasureTextWidth(Graphics g);
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
if (((e.Button == MouseButtons.Left) && this.rectBorder.Contains(e.X, e.Y)) && (this.DropDownMenu != null))
{
this.DropDownMenu.Show(this, new System.Drawing.Point(0, base.Height), 3);
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if ((this.mouseStatus != MouseStatus.Down) && this.rectBorder.Contains(e.X, e.Y))
{
this.mouseStatus = MouseStatus.Down;
this.Refresh();
}
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.mouseStatus = MouseStatus.Normal;
this.Refresh();
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (this.mouseStatus != MouseStatus.Normal)
{
if (!this.rectBorder.Contains(e.X, e.Y))
{
if (base.TextToolTip != null)
{
base.TextToolTip.Active = false;
}
this.mouseStatus = MouseStatus.Normal;
this.Refresh();
}
}
else if (this.rectBorder.Contains(e.X, e.Y))
{
if (base.TextToolTip != null)
{
base.TextToolTip.Active = true;
}
this.mouseStatus = MouseStatus.Hover;
this.Refresh();
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (this.mouseStatus == MouseStatus.Down)
{
if (this.rectBorder.Contains(e.X, e.Y))
{
this.mouseStatus = MouseStatus.Hover;
}
else
{
this.mouseStatus = MouseStatus.Normal;
}
this.Refresh();
}
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
this.PaintText(g);
if (this.DropDownButtonImage != null)
{
g.DrawImage(this.DropDownButtonImage, this.rectDropDownButtonImage);
}
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
Graphics g = pevent.Graphics;
this.AdjustSize(g);
if ((this.mouseStatus == MouseStatus.Hover) || this.isMenuPopup)
{
this.PaintMouseHoverBackground(g);
}
else if (this.mouseStatus == MouseStatus.Down)
{
this.PaintMouseDownBackground(g);
}
else
{
this.PaintBackground(g);
}
}
protected virtual void PaintBackground(Graphics g)
{
}
protected virtual void PaintMouseDownBackground(Graphics g)
{
using (Brush brush = new SolidBrush(this.MouseDownBackColor))
{
g.FillRectangle(brush, this.rectBorder);
}
using (Pen pen = new Pen(this.MouseDownBorderColor))
{
g.DrawRectangle(pen, this.rectBorder);
DrawHelper.DrawBackgroundImage(g, this.MouseDownBackgroundImage, this.rectBackgroundImage);
}
}
protected virtual void PaintMouseHoverBackground(Graphics g)
{
using (Brush brush = new SolidBrush(this.MouseOverBackColor))
{
g.FillRectangle(brush, this.rectBorder);
}
using (Pen pen = new Pen(this.MouseOverBorderColor))
{
g.DrawRectangle(pen, this.rectBorder);
DrawHelper.DrawBackgroundImage(g, this.MouseOverBackgroundImage, this.rectBackgroundImage);
}
}
protected abstract void PaintText(Graphics g);
public Color BackColor
{
get
{
return this.backColor;
}
set
{
this.backColor = 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 Color MouseDownBackColor
{
get
{
return this.mouseDownBackColor;
}
set
{
this.mouseDownBackColor = value;
}
}
public Image MouseDownBackgroundImage
{
get
{
if (this.mouseDownBackgroundImage == null)
{
return this.mouseOverBackgroundImage;
}
return this.mouseDownBackgroundImage;
}
set
{
this.mouseDownBackgroundImage = value;
}
}
public Color MouseDownBorderColor
{
get
{
return this.mouseDownBorderColor;
}
set
{
this.mouseDownBorderColor = value;
}
}
public Color MouseOverBackColor
{
get
{
return this.mouseOverBackColor;
}
set
{
this.mouseOverBackColor = value;
}
}
public Image MouseOverBackgroundImage
{
get
{
return this.mouseOverBackgroundImage;
}
set
{
this.mouseOverBackgroundImage = value;
}
}
public Color MouseOverBorderColor
{
get
{
return this.mouseOverBorderColor;
}
set
{
this.mouseOverBorderColor = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -