You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.4 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JwKdsV.Component
{
public class TouchButtonX : DoubleBufferPanelX
{
private Label label = null;
public TouchButtonX()
{
this.DoubleBuffered = true;
label = new Label();
label.Dock = DockStyle.Fill;
label.AutoSize = false;
label.Text = this._text;
label.TextAlign = ContentAlignment.MiddleCenter;
label.MouseDown += Label_MouseDown;
label.MouseUp += Label_MouseUp;
this.Controls.Add(label);
this.BackColor = this._backColor1;
}
private void Label_MouseUp(object sender, MouseEventArgs e)
{
OnMouseUp(e);
}
private void Label_MouseDown(object sender, MouseEventArgs e)
{
OnMouseDown(e);
}
private string _keyCode = "";
public string KeyCode
{
get { return this._keyCode; }
set { this._keyCode = value; }
}
private Color _backColor1 = Color.Moccasin;
public Color BackColor1
{
get { return this._backColor1; }
set
{
this._backColor1 = value;
this.BackColor = this._backColor1;
}
}
private Color _backColor2 = Color.Tan;
public Color BackColor2
{
get { return this._backColor2; }
set
{
this._backColor2 = value;
}
}
private string _text = string.Empty;
public string Text1
{
get
{
return _text;
}
set
{
this._text = value;
this.label.Text = this._text;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if(e.Button == MouseButtons.Left)
{
this.BackColor = this._backColor2;
this.OnClick(e);
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (e.Button == MouseButtons.Left)
{
this.BackColor = this._backColor1;
}
}
}
}