using Bro.Common.Helper; using Bro.Common.Model; using Bro.UI.Model.Winform; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Design; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Bro.M071.Process.UI { public class KeyIndicator : ElementBase { [Browsable(false)] public override string ID { get => base.ID; set => base.ID = value; } [Browsable(false)] public override string Name { get => base.Name; set => base.Name = value; } [Browsable(false)] public override Font Font { get => base.Font; set => base.Font = value; } [Browsable(false)] public override int FontDistance { get => base.FontDistance; set => base.FontDistance = value; } [Browsable(false)] public override int Index { get => base.Index; set => base.Index = value; } [Browsable(false)] public override bool IsShowRemark { get => base.IsShowRemark; set => base.IsShowRemark = value; } [Browsable(false)] public override bool IsEnabled { get => base.IsEnabled; set => base.IsEnabled = value; } [Category("显示设置")] [Description("标签显示区域")] [DisplayName("标签显示区域")] public Rectangle DisplayRect { get; set; } = new Rectangle(); [Browsable(false)] public string Text { get; set; } = ""; [Browsable(false)] public bool? ResultState { get; set; } = null; public KeyIndicator() { } public KeyIndicator(string id, Rectangle rect) { ID = id; DisplayRect = rect; } public override object Clone() { return new KeyIndicator() { DisplayRect = this.DisplayRect, }; } protected override void SetSelectedPen() { Pen = new Pen(Color.Red, 6); } public override void Draw(Graphics g) { g.DrawRectangle(Pen, DisplayRect); RectangleF rectFill = new RectangleF(DisplayRect.X + 1, DisplayRect.Y + 1, DisplayRect.Width - 2, DisplayRect.Height - 2); if (ResultState != null) { var txtSize = g.MeasureString(Text, Font); Color backColor = Color.Green; Color foreColor = Color.Black; if (!ResultState.Value) { backColor = Color.Red; foreColor = Color.White; } g.DrawString(Text, Font, new SolidBrush(foreColor), (float)(DisplayRect.X + DisplayRect.Width / 2.0 - txtSize.Width / 2.0), (float)(DisplayRect.Y + DisplayRect.Height / 2.0 - txtSize.Height / 2.0)); g.FillRectangle(new SolidBrush(Color.FromArgb(55, backColor)), rectFill); } } public override string GetDisplayText() { return $"{DisplayRect.X} {DisplayRect.Y} {DisplayRect.Width} {DisplayRect.Height}"; } public override bool IsIntersect(Rectangle rect) { return false; } public override bool IsMouseHover(Point p) { return false; } public override bool IsMouseInSide(Point p) { return p.X >= DisplayRect.X && p.X <= DisplayRect.X + DisplayRect.Width && p.Y >= DisplayRect.Y && p.Y <= DisplayRect.Y + DisplayRect.Height; } public override bool IsMouseCanMoveElement(Point p) { return IsMouseInSide(p); } public override void OnKeyDown(object sender, KeyEventArgs e) { } public override void OnKeyUp(object sender, KeyEventArgs e) { } public override void OnMouseDownWhenNew(Point p) { } public override void OnMouseMoveWhenNew(Point p) { } public override void OnMouseUpWhenNew(Point p) { } public override void Translate(int x, int y) { DisplayRect = new Rectangle(DisplayRect.X + x, DisplayRect.Y + y, DisplayRect.Width, DisplayRect.Height); } public override void Relocate(Point point) { DisplayRect = new Rectangle(point.X - DisplayRect.Width / 2, point.Y - DisplayRect.Height / 2, DisplayRect.Width, DisplayRect.Height); } public override bool IsMouseCanStretchBottom(Point p) { return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width / 2)) < 10 && Math.Abs(p.Y - DisplayRect.Y - DisplayRect.Height) < 10; } public override bool IsMouseCanStretchRight(Point p) { return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < 10 && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height / 2)) < 10; } public override bool IsMouseCanStretchRightLowerCorner(Point p) { return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < 10 && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height)) < 10; } int x, y = 0; public override void StretchBottom(Point p) { if (p.Y > DisplayRect.Y) { DisplayRect = new Rectangle(DisplayRect.X, DisplayRect.Y, DisplayRect.Width, p.Y - DisplayRect.Y); } } public override void StretchRight(Point p) { if (p.X > DisplayRect.X) { DisplayRect = new Rectangle(DisplayRect.X, DisplayRect.Y, p.X - DisplayRect.X, DisplayRect.Height); } } public override void StretchRightLowerCorner(Point p) { if (p.X > DisplayRect.X && p.Y > DisplayRect.Y) { DisplayRect = new Rectangle(DisplayRect.X, DisplayRect.Y, p.X - DisplayRect.X, p.Y - DisplayRect.Y); } } protected override void DrawResult(Graphics g) { } } }