|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
using System.Drawing.Text;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Controls.ChemicalWeighing
|
|
|
|
|
{
|
|
|
|
|
[DefaultEvent("OnSwitchChanged")]
|
|
|
|
|
[Description("一个开关控件,可以在开关两种状态之间进行选择")]
|
|
|
|
|
public partial class HslSwitch : UserControl
|
|
|
|
|
{
|
|
|
|
|
public HslSwitch()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
this.sf = new StringFormat();
|
|
|
|
|
this.sf.Alignment = StringAlignment.Center;
|
|
|
|
|
this.sf.LineAlignment = StringAlignment.Center;
|
|
|
|
|
base.SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
|
|
|
|
|
base.SetStyle(ControlStyles.ResizeRedraw, true);
|
|
|
|
|
base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
|
|
|
|
base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
|
|
|
|
|
base.AutoScaleMode = AutoScaleMode.None;
|
|
|
|
|
this.BackColor = Color.Transparent;
|
|
|
|
|
this.Cursor = Cursors.Hand;
|
|
|
|
|
base.Name = "HslSwitch";
|
|
|
|
|
base.ResumeLayout(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开关按钮发生变化的事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x14000009 RID: 9
|
|
|
|
|
// (add) Token: 0x06000775 RID: 1909 RVA: 0x00042DC0 File Offset: 0x00040FC0
|
|
|
|
|
// (remove) Token: 0x06000776 RID: 1910 RVA: 0x00042DF8 File Offset: 0x00040FF8
|
|
|
|
|
[Category("Action")]
|
|
|
|
|
[Description("点击了按钮开发后触发")]
|
|
|
|
|
|
|
|
|
|
public event Action<object, bool> OnSwitchChanged;
|
|
|
|
|
|
|
|
|
|
// Token: 0x06000777 RID: 1911 RVA: 0x00042E30 File Offset: 0x00041030
|
|
|
|
|
private Point GetCenterPoint(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
bool flag = height > width;
|
|
|
|
|
Point result;
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
result = new Point(width / 2, width / 2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = new Point(height / 2, height / 2);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或设置控件的背景色
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x17000254 RID: 596
|
|
|
|
|
// (get) Token: 0x06000778 RID: 1912 RVA: 0x00042E65 File Offset: 0x00041065
|
|
|
|
|
// (set) Token: 0x06000779 RID: 1913 RVA: 0x00042E6D File Offset: 0x0004106D
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Description("获取或设置控件的背景色")]
|
|
|
|
|
[Category("HslControls")]
|
|
|
|
|
[DefaultValue(typeof(Color), "Transparent")]
|
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Always)]
|
|
|
|
|
public override Color BackColor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.BackColor;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.BackColor = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或设置开关按钮的背景色
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x17000255 RID: 597
|
|
|
|
|
// (get) Token: 0x0600077A RID: 1914 RVA: 0x00042E78 File Offset: 0x00041078
|
|
|
|
|
// (set) Token: 0x0600077B RID: 1915 RVA: 0x00042E90 File Offset: 0x00041090
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Description("获取或设置开关按钮的背景色")]
|
|
|
|
|
[Category("HslControls")]
|
|
|
|
|
[DefaultValue(typeof(Color), "DimGray")]
|
|
|
|
|
public Color SwitchBackground
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.color_switch_background;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.color_switch_background = value;
|
|
|
|
|
Brush brush = this.brush_switch_background;
|
|
|
|
|
if (brush != null)
|
|
|
|
|
{
|
|
|
|
|
brush.Dispose();
|
|
|
|
|
}
|
|
|
|
|
Pen pen = this.pen_switch_background;
|
|
|
|
|
if (pen != null)
|
|
|
|
|
{
|
|
|
|
|
pen.Dispose();
|
|
|
|
|
}
|
|
|
|
|
this.brush_switch_background = new SolidBrush(this.color_switch_background);
|
|
|
|
|
this.pen_switch_background = new Pen(this.color_switch_background, 2f);
|
|
|
|
|
base.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或设置开关按钮的前景色
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x17000256 RID: 598
|
|
|
|
|
// (get) Token: 0x0600077C RID: 1916 RVA: 0x00042EF8 File Offset: 0x000410F8
|
|
|
|
|
// (set) Token: 0x0600077D RID: 1917 RVA: 0x00042F10 File Offset: 0x00041110
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Description("获取或设置开关按钮的前景色")]
|
|
|
|
|
[Category("HslControls")]
|
|
|
|
|
[DefaultValue(typeof(Color), "[36, 36, 36]")]
|
|
|
|
|
public Color SwitchForeground
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.color_switch_foreground;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.color_switch_foreground = value;
|
|
|
|
|
this.brush_switch_foreground = new SolidBrush(this.color_switch_foreground);
|
|
|
|
|
base.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或设置开关按钮的开合状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x17000257 RID: 599
|
|
|
|
|
// (get) Token: 0x0600077E RID: 1918 RVA: 0x00042F34 File Offset: 0x00041134
|
|
|
|
|
// (set) Token: 0x0600077F RID: 1919 RVA: 0x00042F4C File Offset: 0x0004114C
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Description("获取或设置开关按钮的开合状态")]
|
|
|
|
|
[Category("HslControls")]
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool SwitchStatus
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.switch_status;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
bool flag = value != this.switch_status;
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
this.switch_status = value;
|
|
|
|
|
base.Invalidate();
|
|
|
|
|
Action<object, bool> onSwitchChanged = this.OnSwitchChanged;
|
|
|
|
|
if (onSwitchChanged != null)
|
|
|
|
|
{
|
|
|
|
|
onSwitchChanged(this, this.switch_status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或设置两种开关状态的文本描述,例如:"Off;On"
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x17000258 RID: 600
|
|
|
|
|
// (get) Token: 0x06000780 RID: 1920 RVA: 0x00042F94 File Offset: 0x00041194
|
|
|
|
|
// (set) Token: 0x06000781 RID: 1921 RVA: 0x00042FAC File Offset: 0x000411AC
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Description("获取或设置两种开关状态的文本描述,例如:Off;On")]
|
|
|
|
|
[Category("HslControls")]
|
|
|
|
|
[DefaultValue("关;开")]
|
|
|
|
|
public string SwitchStatusDescription
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.description;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.description = value;
|
|
|
|
|
base.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或设置当前控件的文本
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x17000259 RID: 601
|
|
|
|
|
// (get) Token: 0x06000782 RID: 1922 RVA: 0x00042FC0 File Offset: 0x000411C0
|
|
|
|
|
// (set) Token: 0x06000783 RID: 1923 RVA: 0x00042FD8 File Offset: 0x000411D8
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Description("获取或设置当前控件的文本")]
|
|
|
|
|
[Category("HslControls")]
|
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Always)]
|
|
|
|
|
[Bindable(true)]
|
|
|
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.Text;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Text = value;
|
|
|
|
|
base.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取或设置当前控件的文本的颜色
|
|
|
|
|
/// </summary>
|
|
|
|
|
// Token: 0x1700025A RID: 602
|
|
|
|
|
// (get) Token: 0x06000784 RID: 1924 RVA: 0x00042FEC File Offset: 0x000411EC
|
|
|
|
|
// (set) Token: 0x06000785 RID: 1925 RVA: 0x00043004 File Offset: 0x00041204
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
[Description("获取或设置当前控件的文本的颜色")]
|
|
|
|
|
[Category("HslControls")]
|
|
|
|
|
[DefaultValue(typeof(Color), "Black")]
|
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Always)]
|
|
|
|
|
public override Color ForeColor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.textForeColor;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.textForeColor = value;
|
|
|
|
|
this.textForeBrush.Dispose();
|
|
|
|
|
this.textForeBrush = new SolidBrush(value);
|
|
|
|
|
base.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
// Token: 0x06000786 RID: 1926 RVA: 0x00043030 File Offset: 0x00041230
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
bool flag = false;
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
|
|
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
|
|
|
|
this.PaintHslControls(e.Graphics, base.Width, base.Height);
|
|
|
|
|
base.OnPaint(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc cref="M:HslControls.HslArrow.PaintHslControls(System.Drawing.Graphics,System.Single,System.Single)" />
|
|
|
|
|
// Token: 0x06000787 RID: 1927 RVA: 0x00043088 File Offset: 0x00041288
|
|
|
|
|
public void PaintHslControls(Graphics g, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
bool flag = false;
|
|
|
|
|
if (!flag)
|
|
|
|
|
{
|
|
|
|
|
string[] array = this.description.Split(new char[]
|
|
|
|
|
{
|
|
|
|
|
';'
|
|
|
|
|
}, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
string text = string.Empty;
|
|
|
|
|
string text2 = string.Empty;
|
|
|
|
|
bool flag2 = array.Length != 0;
|
|
|
|
|
if (flag2)
|
|
|
|
|
{
|
|
|
|
|
text = array[0];
|
|
|
|
|
}
|
|
|
|
|
bool flag3 = array.Length > 1;
|
|
|
|
|
if (flag3)
|
|
|
|
|
{
|
|
|
|
|
text2 = array[1];
|
|
|
|
|
}
|
|
|
|
|
Point centerPoint = this.GetCenterPoint(width, height);
|
|
|
|
|
g.TranslateTransform((float)centerPoint.X, (float)centerPoint.Y);
|
|
|
|
|
int num = 45 * (centerPoint.X * 2 - 30) / 130;
|
|
|
|
|
bool flag4 = num < 5;
|
|
|
|
|
if (!flag4)
|
|
|
|
|
{
|
|
|
|
|
Rectangle rect = new Rectangle(-num - 4, -num - 4, 2 * num + 8, 2 * num + 8);
|
|
|
|
|
Rectangle rect2 = new Rectangle(-num, -num, 2 * num, 2 * num);
|
|
|
|
|
g.DrawEllipse(this.pen_switch_background, rect);
|
|
|
|
|
g.FillEllipse(this.brush_switch_background, rect2);
|
|
|
|
|
float angle = -36f;
|
|
|
|
|
bool flag5 = this.switch_status;
|
|
|
|
|
if (flag5)
|
|
|
|
|
{
|
|
|
|
|
angle = 36f;
|
|
|
|
|
}
|
|
|
|
|
g.RotateTransform(angle);
|
|
|
|
|
int num2 = 20 * (centerPoint.X * 2 - 30) / 130;
|
|
|
|
|
Rectangle rect3 = new Rectangle(-centerPoint.X / 8, -num - num2, centerPoint.X / 4, num * 2 + num2 * 2);
|
|
|
|
|
g.FillRectangle(this.brush_switch_foreground, rect3);
|
|
|
|
|
Rectangle rect4 = new Rectangle(-centerPoint.X / 16, -num - 10, centerPoint.X / 8, centerPoint.X * 3 / 8);
|
|
|
|
|
g.FillEllipse(this.switch_status ? Brushes.LimeGreen : Brushes.Tomato, rect4);
|
|
|
|
|
Rectangle r = new Rectangle(-50, -num - num2 - 15, 100, 15);
|
|
|
|
|
g.DrawString(this.switch_status ? text2 : text, this.Font, this.switch_status ? Brushes.LimeGreen : Brushes.Tomato, r, this.sf);
|
|
|
|
|
g.ResetTransform();
|
|
|
|
|
bool flag6 = height - Math.Min(width, height) > 0;
|
|
|
|
|
if (flag6)
|
|
|
|
|
{
|
|
|
|
|
bool flag7 = !string.IsNullOrEmpty(this.Text);
|
|
|
|
|
if (flag7)
|
|
|
|
|
{
|
|
|
|
|
g.DrawString(this.Text, this.Font, this.textForeBrush, new Rectangle(0, Math.Min(width, height) - 15, Math.Min(width, height), height - Math.Min(width, height) + 15), this.sf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 鼠标的点击事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">鼠标的点击事件</param>
|
|
|
|
|
// Token: 0x06000788 RID: 1928 RVA: 0x00043308 File Offset: 0x00041508
|
|
|
|
|
protected override void OnMouseClick(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
bool flag = e.Button == MouseButtons.Left;
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
this.SwitchStatus = !this.SwitchStatus;
|
|
|
|
|
}
|
|
|
|
|
base.OnClick(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过当前方法来修改控件的状态,而不触发状态改变的事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="status">新增状态值</param>
|
|
|
|
|
// Token: 0x06000789 RID: 1929 RVA: 0x00043341 File Offset: 0x00041541
|
|
|
|
|
public void ChangeSwitchStatus(bool status)
|
|
|
|
|
{
|
|
|
|
|
this.switch_status = status;
|
|
|
|
|
base.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B0 RID: 944
|
|
|
|
|
private Color textForeColor = Color.Black;
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B1 RID: 945
|
|
|
|
|
private Brush textForeBrush = new SolidBrush(Color.Black);
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B2 RID: 946
|
|
|
|
|
private Color color_switch_background = Color.DimGray;
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B3 RID: 947
|
|
|
|
|
private Brush brush_switch_background = new SolidBrush(Color.DimGray);
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B4 RID: 948
|
|
|
|
|
private Pen pen_switch_background = new Pen(Color.DimGray, 2f);
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B5 RID: 949
|
|
|
|
|
private bool switch_status = false;
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B6 RID: 950
|
|
|
|
|
private Color color_switch_foreground = Color.FromArgb(36, 36, 36);
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B7 RID: 951
|
|
|
|
|
private Brush brush_switch_foreground = new SolidBrush(Color.FromArgb(36, 36, 36));
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B8 RID: 952
|
|
|
|
|
private StringFormat sf = null;
|
|
|
|
|
|
|
|
|
|
// Token: 0x040003B9 RID: 953
|
|
|
|
|
private string description = "关;开";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|