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.
lj_plc/Controls/Mesnac.Controls.ChemicalWei.../HslLanternSimple.cs

274 lines
9.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
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
{
[Description("一个圆形的信号灯,支持设置颜色,是否渐变")]
public partial class HslLanternSimple : UserControl
{
public HslLanternSimple()
{
InitializeComponent();
base.AutoScaleMode = AutoScaleMode.None;
this.BackColor = Color.Transparent;
base.Name = "HslLanternSimple";
base.Size = new Size(78, 94);
base.ResumeLayout(false);
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);
//LanternBackground = Color.Transparent;
}
// Token: 0x040002C0 RID: 704
private Color colorBackground = Color.LimeGreen;
// Token: 0x040002C1 RID: 705
private Brush brushBackground = new SolidBrush(Color.LimeGreen);
// Token: 0x040002C2 RID: 706
private StringFormat sf = null;
// Token: 0x040002C3 RID: 707
private Color centerColor = Color.White;
// Token: 0x040002C4 RID: 708
private bool isUseGradientColor = false;
/// <summary>
/// 获取或设置控件的背景色
/// </summary>
// Token: 0x170001B1 RID: 433
// (get) Token: 0x0600057F RID: 1407 RVA: 0x000362BC File Offset: 0x000344BC
// (set) Token: 0x06000580 RID: 1408 RVA: 0x000362C4 File Offset: 0x000344C4
[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: 0x170001B2 RID: 434
// (get) Token: 0x06000581 RID: 1409 RVA: 0x000362D0 File Offset: 0x000344D0
// (set) Token: 0x06000582 RID: 1410 RVA: 0x000362E8 File Offset: 0x000344E8
[Browsable(true)]
[Description("获取或设置信号灯的背景色")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "LimeGreen")]
public Color LanternBackground
{
get
{
return this.colorBackground;
}
set
{
this.colorBackground = value;
Brush brush = this.brushBackground;
if (brush != null)
{
brush.Dispose();
}
this.brushBackground = new SolidBrush(this.colorBackground);
base.Invalidate();
}
}
/// <summary>
/// 获取或设置中心点的颜色当且仅当UseGradientColor属性为True时生效
/// </summary>
// Token: 0x170001B3 RID: 435
// (get) Token: 0x06000583 RID: 1411 RVA: 0x0003631C File Offset: 0x0003451C
// (set) Token: 0x06000584 RID: 1412 RVA: 0x00036334 File Offset: 0x00034534
[Browsable(true)]
[Description("获取或设置中心点的颜色当且仅当UseGradientColor属性为True时生效")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "White")]
public Color CenterBackground
{
get
{
return this.centerColor;
}
set
{
this.centerColor = value;
base.Invalidate();
}
}
/// <summary>
/// 获取或设置当前的灯信号是否启用渐变色的画刷
/// </summary>
// Token: 0x170001B4 RID: 436
// (get) Token: 0x06000585 RID: 1413 RVA: 0x00036348 File Offset: 0x00034548
// (set) Token: 0x06000586 RID: 1414 RVA: 0x00036360 File Offset: 0x00034560
[Browsable(true)]
[Description("获取或设置当前的灯信号是否启用渐变色的画刷")]
[Category("HslControls")]
[DefaultValue(false)]
public bool UseGradientColor
{
get
{
return this.isUseGradientColor;
}
set
{
this.isUseGradientColor = value;
base.Invalidate();
}
}
/// <summary>
/// 获取或设置当前控件的文本
/// </summary>
// Token: 0x170001B5 RID: 437
// (get) Token: 0x06000587 RID: 1415 RVA: 0x00036374 File Offset: 0x00034574
// (set) Token: 0x06000588 RID: 1416 RVA: 0x0003638C File Offset: 0x0003458C
[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: 0x06000589 RID: 1417 RVA: 0x0003639E File Offset: 0x0003459E
public void PerformClick()
{
this.OnClick(new EventArgs());
}
/// <inheritdoc />
// Token: 0x0600057D RID: 1405 RVA: 0x00035FA0 File Offset: 0x000341A0
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
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: 0x0600057E RID: 1406 RVA: 0x00036004 File Offset: 0x00034204
public void PaintHslControls(Graphics g, int width, int height)
{
bool flag = false;
if (!flag)
{
int num = Math.Min(width, height);
num--;
Point point = new Point(num / 2, num / 2);
g.TranslateTransform((float)point.X, (float)point.Y);
float num2 = (float)(point.X * 17) / 20f;
float num3 = (float)point.X / 20f;
bool flag2 = num2 < 2f;
if (!flag2)
{
RectangleF rect = new RectangleF(-num2 - 2f * num3, -num2 - 2f * num3, 2f * num2 + 4f * num3, 2f * num2 + 4f * num3);
RectangleF rect2 = new RectangleF(-num2, -num2, 2f * num2, 2f * num2);
using (Pen pen = new Pen(this.colorBackground, num3))
{
g.DrawEllipse(pen, rect);
}
bool flag3 = !this.UseGradientColor;
if (flag3)
{
g.FillEllipse(this.brushBackground, rect2);
}
else
{
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.AddEllipse(-num2, -num2, 2f * num2, 2f * num2);
PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath);
pathGradientBrush.CenterPoint = new Point(0, 0);
pathGradientBrush.InterpolationColors = new ColorBlend
{
Positions = new float[]
{
0f,
1f
},
Colors = new Color[]
{
this.colorBackground,
this.centerColor
}
};
g.FillEllipse(pathGradientBrush, rect2);
using (Pen pen2 = new Pen(this.colorBackground))
{
g.DrawEllipse(pen2, -num2, -num2, 2f * num2, 2f * num2);
}
pathGradientBrush.Dispose();
graphicsPath.Dispose();
}
g.TranslateTransform((float)(-(float)point.X), (float)(-(float)point.Y));
bool flag4 = height - num > 0;
if (flag4)
{
bool flag5 = !string.IsNullOrEmpty(this.Text);
if (flag5)
{
using (Brush brush = new SolidBrush(this.ForeColor))
{
g.DrawString(this.Text, this.Font, brush, new Rectangle(0, num, num, height - num), this.sf);
}
}
}
}
}
}
}
}