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; using System.Drawing.Drawing2D; using IntelligentControlForsx.Service; using IntelligentControlForsx.Common; using IntelligentControlForsx.Properties; namespace IntelligentControlForsx.MyControls { public partial class MatrixBlock : UserControl { public MatrixBlock() { InitializeComponent(); // ControlStyles.UserPaint | this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);//开启双缓冲 tip = new ToolTip(); // 鼠标进入时显示tips tip.AutoPopDelay = 10000; tip.InitialDelay = 200; tip.ReshowDelay = 200; tip.ShowAlways = true; topLineColor= BottomLineColor = BackColor; } ToolTip tip; string deviceId; string deviceModel; string stationId; double windSpeed; double power; double status; bool isLock; long ts; // 条纹的颜色 Color topLineColor,BottomLineColor; Font windturbineTextFont = new Font("微软雅黑", 7.5f); Font paramTextFont = new Font("微软雅黑", 6.5f); [Category("Xproperty"), Description("风机名称的字体"), DefaultValue(typeof(Font), "微软雅黑, 7.4f")] public Font WindTurbineFont { get { return windturbineTextFont; } set { windturbineTextFont = value; this.Invalidate(RecWindturbineText); } } [Category("Xproperty"), Description("风机参数的字体"), DefaultValue(typeof(Font), "微软雅黑, 6.4f")] public Font ParamTextFont { get { return paramTextFont; } set { paramTextFont = value; this.Invalidate(RecRight); } } [Browsable(true), Category("Xproperty")] public string DeviceId { get { return deviceId; } set { deviceId = value; Invalidate(RecWindturbineText); //lblDeviceId.Text = value; } } [Browsable(true), Category("Xproperty")] public double WindSpeed { get { return windSpeed; } set { windSpeed = value; Invalidate(RecSpeed); //lblWindSpeed.Text = Convert.ToDouble(value).ToString("0.00") + "m/s"; } } [Browsable(true), Category("Xproperty")] public double Power { get { return power; } set { power = value; Invalidate(RecPower); //lblPower.Text = Convert.ToDouble(value).ToString("0.00") + "kw"; } } [Browsable(true), Category("Xproperty")] public double Status { get { return status; } set { status = value; this.BackColor = getBackColor(value); topLineColor = getBackColor(value); Invalidate(); } } public bool IsLock { set { BottomLineColor = value ? Color.Yellow : topLineColor; isLock = value; Invalidate(); } get { return isLock; } } private double lokcValue; public double LockValue { get { return lokcValue; } set { lokcValue = value; } } public string DeviceModel { get { return deviceModel; } set { deviceModel = value; } } public string StationId { get { return stationId; } set { stationId = value; } } public long Ts { get { return ts; } set { ts = value; } } private Color getBackColor(double status) { int st = Convert.ToInt32(status); switch (st) { //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS case 0: //停机状态 return Color.FromArgb(176, 151, 63); case 1: //上电状态 return Color.FromArgb(177, 14, 126); case 2: //待机状态 return Color.FromArgb(15, 141, 106); case 3: //启动状态 return Color.FromArgb(14, 72, 91); case 4: //并网状态 return Color.FromArgb(15, 135, 170); case 5: //故障状态 return Color.FromArgb(170, 15, 59); case 6: //维护状态 return Color.FromArgb(204, 83, 51); case 7: //离线状态 return Color.FromArgb(134, 150, 165); default: return BackColor; } } #region 区域 private Rectangle RecTopLine { get { return new Rectangle(0, 0, this.Width, 2); } } private Rectangle RecWindturbineText { get { return new Rectangle(0, 2, Width * 4 / 9, (this.Height - 4)-12); } } private Rectangle RecRight { get { return new Rectangle(Width * 4 / 9, 2, Width * 5 / 9, this.Height - 4); } } private Rectangle RecSpeed { get { return new Rectangle(Width * 4 / 9, 2, Width * 5 / 9, (this.Height - 4) / 2); } } private Rectangle RecPower { get { // 长度总是不够 //return new Rectangle(Width * 4 / 9, Height / 2, Width * 5 / 9, (this.Height - 4) / 2); return new Rectangle(12 + 3, Height / 2, Width - 15, (Height - 4) / 2); } } private Rectangle RecBottomLine { get { return new Rectangle(0, this.Height - 2, Width, 2); } } #endregion #region 事件 public event EventHandler MyMouseDown; public event EventHandler MyMouseUp; private void MatrixBlock_DoubleClick(object sender, EventArgs e) { string windturbineId = CommonMethod.GetLongWindturbineId(this.deviceId); string powerStationId = this.stationId; NavService.Instance.NavForWindturbine("pictureBoxParamters", windturbineId, powerStationId); } #endregion private string getBeginTime(long ts) { if (ts < 10000) return ""; DateTime dt = CommonMethod.ConvertIntDateTime(ts); return dt.ToString("yyyy-MM-dd hh:mm:ss"); } private string getTimeSpan(long ts) { if (ts < 10000) return ""; DateTime dt = CommonMethod.ConvertIntDateTime(ts); TimeSpan tts = DateTime.Now - dt; return (long)tts.TotalMinutes + ""; } public bool testShow(double status1, bool autoFilter, double minSpeed = 0, double maxSpeed = 0, double minPower = 0, double maxPower = 0) { bool result = true; if (status1 == 9) { if (autoFilter) { if (minSpeed != 0 || maxSpeed != 0) { if (minPower == 0 && maxPower == 0) { if (windSpeed >= minSpeed && windSpeed <= maxSpeed) result = true; else result = false; } else { if (windSpeed >= minSpeed && windSpeed <= maxSpeed && power >= minPower && power <= maxPower) result = true; else result = false; } } else { if (power >= minPower && power <= maxPower) result = true; else result = false; } } } else if (status1 == status) { if (autoFilter) { if (windSpeed >= minSpeed && windSpeed <= maxSpeed && power >= minPower && power <= maxPower) result = true; else result = false; } } else { result = false; } return result; } protected override void OnPaint(PaintEventArgs e) { // 先在内存上创建一个Graphics对象,然后画出所有图形,之后绘制在控件上 Rectangle rect = e.ClipRectangle; BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle); Graphics g = myBuffer.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighSpeed; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.Clear(this.BackColor); // 顶部线 SolidBrush tmpBrush = new SolidBrush(topLineColor); g.FillRectangle(tmpBrush, RecTopLine); // 文字格式 StringFormat strFormat = new StringFormat();//文本格式 strFormat.LineAlignment = StringAlignment.Center;//垂直居中 strFormat.Alignment = StringAlignment.Center;//水平 // id tmpBrush = new SolidBrush(Color.White); g.DrawString(DeviceId, WindTurbineFont, tmpBrush, RecWindturbineText, strFormat); // 风速和功率 strFormat.Alignment = StringAlignment.Far;//水平居右 g.DrawString(WindSpeed.ToString("F2") + "m/s", ParamTextFont, tmpBrush, RecSpeed, strFormat); g.DrawString(Power.ToString("F2") + "kWh", ParamTextFont, tmpBrush, RecPower, strFormat); // 底部线 tmpBrush = new SolidBrush(BottomLineColor); g.FillRectangle(tmpBrush, RecBottomLine); // time 图标 g.DrawImage(Resources.time, 1, Height - 13, 12, 12); base.OnPaint(e); myBuffer.Render(e.Graphics); myBuffer.Dispose();//释放资源 g.Dispose(); } } }