增加按钮图标的支持

master
lhiven 2 years ago
parent 65387f6f9b
commit 9a44b4eade

@ -30,12 +30,13 @@
{ {
this.lblTips = new System.Windows.Forms.Label(); this.lblTips = new System.Windows.Forms.Label();
this.lbl = new System.Windows.Forms.Label(); this.lbl = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout(); this.SuspendLayout();
// //
// lblTips // lblTips
// //
this.lblTips.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.lblTips.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lblTips.BackColor = System.Drawing.Color.Transparent; this.lblTips.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.lblTips.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblTips.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblTips.ForeColor = System.Drawing.Color.White; this.lblTips.ForeColor = System.Drawing.Color.White;
this.lblTips.ImageIndex = 0; this.lblTips.ImageIndex = 0;
@ -50,7 +51,7 @@
// //
this.lbl.Anchor = System.Windows.Forms.AnchorStyles.None; this.lbl.Anchor = System.Windows.Forms.AnchorStyles.None;
this.lbl.BackColor = System.Drawing.Color.Transparent; this.lbl.BackColor = System.Drawing.Color.Transparent;
this.lbl.Font = new System.Drawing.Font("Microsoft YaHei", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lbl.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl.ForeColor = System.Drawing.Color.White; this.lbl.ForeColor = System.Drawing.Color.White;
this.lbl.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.lbl.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.lbl.Location = new System.Drawing.Point(0, 0); this.lbl.Location = new System.Drawing.Point(0, 0);
@ -60,11 +61,26 @@
this.lbl.Text = "自定义按钮"; this.lbl.Text = "自定义按钮";
this.lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lbl.Click += new System.EventHandler(this.lbl_MouseClick); this.lbl.Click += new System.EventHandler(this.lbl_MouseClick);
this.lbl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
this.lbl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseUp);
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Dock = System.Windows.Forms.DockStyle.Left;
this.label1.ForeColor = System.Drawing.Color.White;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(104, 84);
this.label1.TabIndex = 4;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.Paint += new System.Windows.Forms.PaintEventHandler(this.label1_Paint);
// //
// RsButton // RsButton
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Controls.Add(this.lblTips); this.Controls.Add(this.lblTips);
this.Controls.Add(this.lbl); this.Controls.Add(this.lbl);
this.Name = "RsButton"; this.Name = "RsButton";
@ -77,5 +93,6 @@
private System.Windows.Forms.Label lblTips; private System.Windows.Forms.Label lblTips;
public System.Windows.Forms.Label lbl; public System.Windows.Forms.Label lbl;
private System.Windows.Forms.Label label1;
} }
} }

@ -11,8 +11,26 @@ using System.Windows.Forms;
namespace Rs.Controls namespace Rs.Controls
{ {
public enum EButtonIcon
{
None,
EStop,
Reset,
Start,
Stop
}
public partial class RsButton : ControlBase public partial class RsButton : ControlBase
{ {
private EButtonIcon _ButtonType;
public EButtonIcon ButtonType
{
get { return _ButtonType; }
set { _ButtonType = value;
}
}
public RsButton() public RsButton()
{ {
InitializeComponent(); InitializeComponent();
@ -226,7 +244,6 @@ namespace Rs.Controls
e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.FillEllipse(new SolidBrush(m_tipsColor), new Rectangle(0, 0, lblTips.Width - 1, lblTips.Height - 1)); e.Graphics.FillEllipse(new SolidBrush(m_tipsColor), new Rectangle(0, 0, lblTips.Width - 1, lblTips.Height - 1));
System.Drawing.SizeF sizeEnd = e.Graphics.MeasureString(TipsText, lblTips.Font); System.Drawing.SizeF sizeEnd = e.Graphics.MeasureString(TipsText, lblTips.Font);
e.Graphics.DrawString(TipsText, lblTips.Font, new SolidBrush(lblTips.ForeColor), new PointF((lblTips.Width - sizeEnd.Width) / 2, (lblTips.Height - sizeEnd.Height) / 2 + 1)); e.Graphics.DrawString(TipsText, lblTips.Font, new SolidBrush(lblTips.ForeColor), new PointF((lblTips.Width - sizeEnd.Width) / 2, (lblTips.Height - sizeEnd.Height) / 2 + 1));
} }
@ -256,5 +273,33 @@ namespace Rs.Controls
if (this.BtnClick != null) if (this.BtnClick != null)
BtnClick(this, e); BtnClick(this, e);
} }
private void label1_Paint(object sender, PaintEventArgs e)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
FontFamily ff = IconFontHelper.PFCC.Families[0];
Font font = new Font(ff, 40);
switch (ButtonType)
{
case EButtonIcon.None:
break;
case EButtonIcon.EStop:
e.Graphics.DrawString("\ue605", font,new SolidBrush(this.ForeColor), label1.ClientRectangle, sf);
break;
case EButtonIcon.Reset:
e.Graphics.DrawString("\ue600", font, new SolidBrush(this.ForeColor), label1.ClientRectangle, sf);
break;
case EButtonIcon.Start:
e.Graphics.DrawString("\ue6b0", font, new SolidBrush(this.ForeColor), label1.ClientRectangle, sf);
break;
case EButtonIcon.Stop:
e.Graphics.DrawString("\ue629", font, new SolidBrush(this.ForeColor), label1.ClientRectangle, sf);
break;
default:
break;
}
}
} }
} }

Loading…
Cancel
Save