using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PaintDotNet.CustomControl
{
public partial class SelectButton : BaseUserControl
{
private PictureBox pictureBox1;
private Label buttonText;
private string textEX;
public SelectButton()
{
InitializeComponent();
InitializeLanguageText();
}
private void InitializeLanguageText()
{
if(!DesignMode)
{
this.buttonText.Text = PdnResources.GetString("Menu.butto.Text");
this.textEX = PdnResources.GetString("Menu.butto.Text");
}
}
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.buttonText = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLight;
this.pictureBox1.Location = new System.Drawing.Point(1, 1);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(144, 37);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// buttonText
//
this.buttonText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.buttonText.BackColor = System.Drawing.SystemColors.ControlLight;
this.buttonText.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.buttonText.Location = new System.Drawing.Point(2, 2);
this.buttonText.Name = "buttonText";
this.buttonText.Size = new System.Drawing.Size(142, 35);
this.buttonText.TabIndex = 1;
this.buttonText.Text = "按钮";
this.buttonText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.buttonText.Click += new System.EventHandler(this.buttonText_Click);
this.buttonText.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
this.buttonText.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave);
this.buttonText.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
this.buttonText.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
//
// SelectButton
//
this.BackColor = System.Drawing.SystemColors.Highlight;
this.Controls.Add(this.buttonText);
this.Controls.Add(this.pictureBox1);
this.Name = "SelectButton";
this.Size = new System.Drawing.Size(146, 39);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
///
/// 按钮文字显示
///
[Description("按钮显示的文字")]
public string BtnText
{
get { return textEX; }
set
{
textEX = value;
buttonText.Text = textEX;
}
}
///
/// 按钮选中状态
///
private bool selectEX = false;
[Description("按钮显示的文字")]
public bool BtnSelect
{
get { return selectEX; }
set
{
selectEX = value;
if (selectEX)
{
this.BackColor = System.Drawing.SystemColors.Highlight;
this.pictureBox1.BackColor = System.Drawing.SystemColors.Highlight;
}
else
{
this.BackColor = System.Drawing.SystemColors.ControlDark;
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLight;
}
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
this.buttonText.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
this.pictureBox1.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
this.BackColor = System.Drawing.SystemColors.Highlight;
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.buttonText.BackColor = System.Drawing.SystemColors.ControlLight;
if (selectEX)
{
this.pictureBox1.BackColor = System.Drawing.SystemColors.Highlight;
this.BackColor = System.Drawing.SystemColors.Highlight;
}
else
{
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLight;
this.BackColor = System.Drawing.SystemColors.ControlDark;
}
}
public void buttonText_Click(object sender, EventArgs e)
{
OnClick(e);//这句话很关键!!!
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.Focus();
this.pictureBox1.BackColor = System.Drawing.SystemColors.GradientActiveCaption;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
this.pictureBox1.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
}
//————————————————
//版权声明:本文为CSDN博主「bgbgxia」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
//原文链接:https://blog.csdn.net/weixin_42266753/article/details/100803493
}
}