using DevExpress.Drawing.Internal.Fonts.Interop; using DevExpress.Office.Utils; using IStation.WinFrmUI.CalcErQu; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Windows.Forms; namespace IStation.WinFrmUI { public partial class RunTimeRangePanel : Panel { public RunTimeRangePanel() { } /// /// 绘制对象列表 /// List _block_item_list = null; DateTime _startTime = DateTime.Today; /// /// /// /// /// /// public void SetRangePumpCount(List block_item_list) { if(block_item_list == null || block_item_list.Count() == 0) { return; } _startTime = DateTime.Today; this._block_item_list = block_item_list; this.Refresh(); } /// /// 初始化项大小 /// public void InitialItemSize() { //if (_block_item_list == null || !_block_item_list.Any()) // return; //int last_right_x = 10; //int last_loc_y = 10; //for (int i = 0; i < _block_item_list.Count; i++) //{ // var item = _block_item_list[i]; // var current_loc_x = last_right_x; // if (item.TextVisible) // { // if (current_loc_x + item.Width > this.Width - 50) // { // last_loc_y = last_loc_y + item.Height + 10; // current_loc_x = 10; // item.IsLineStartBlck = true; // _block_item_list[i - 1].IsLineEndBlck = true; // } // } // else // { // if (current_loc_x + item.Width > this.Width - 20) // { // last_loc_y = last_loc_y + item.Height + 10; // current_loc_x = 10; // item.IsLineStartBlck = true; // _block_item_list[i - 1].IsLineEndBlck = true; // } // } // if (i == 0) // { // item.IsLineStartBlck = true; // } // if (i == _block_item_list.Count - 1) // { // item.IsLineEndBlck = true; // } // last_right_x = current_loc_x + item.Width; // item.Resize(current_loc_x, last_loc_y); //} this.Refresh(); } #region override // public static Color SelectColor = Color.DarkGreen ; /// /// 重绘事件 /// /// protected override void OnPaint(PaintEventArgs e) { if (DesignMode) return; if (_block_item_list == null || _block_item_list.Count() == 0) return; int today_minute = 24 * 60; base.OnPaint(e); e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;//抗锯齿 e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿 // 设置GDI高质量模式抗锯齿 e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; var g = e.Graphics; float pump_block_height = 22; float pump_block_space = 8; float pump_block_start = 15; int drawWidth = this.Width - 30; using (Brush gpBrush = new SolidBrush(SelectColor)) { foreach (var block in _block_item_list) { float startMinute = Convert.ToSingle( (block.StartTime - _startTime).TotalMinutes * drawWidth / today_minute); float endMinute = Convert.ToSingle((block.EndTime - _startTime).TotalMinutes * drawWidth / today_minute); float _width = endMinute - startMinute; if (block.PumpNumber == 0) { continue; } PointF posi1 = new PointF(startMinute + 15, pump_block_start); RectangleF rect1 = new RectangleF(posi1, new SizeF(_width, pump_block_height)); g.FillRectangle(gpBrush, rect1); if (block.PumpNumber > 1) { PointF posi2 = new PointF(startMinute + 15, pump_block_start + pump_block_height + pump_block_space); RectangleF rect2 = new RectangleF(posi2, new SizeF(_width, pump_block_height)); g.FillRectangle(gpBrush, rect2); } if (block.PumpNumber > 2) { PointF posi3 = new PointF(startMinute + 15, pump_block_start + pump_block_height * 2 + pump_block_space * 2); RectangleF rect3 = new RectangleF(posi3, new SizeF(_width, pump_block_height)); g.FillRectangle(gpBrush, rect3); } if (block.PumpNumber > 3) { PointF posi3 = new PointF(startMinute + 15, pump_block_start + pump_block_height * 3 + pump_block_space * 3); RectangleF rect3 = new RectangleF(posi3, new SizeF(_width, pump_block_height)); g.FillRectangle(gpBrush, rect3); } if (block.PumpNumber > 4) { PointF posi3 = new PointF(startMinute + 15, pump_block_start + pump_block_height * 4 + pump_block_space * 4); RectangleF rect3 = new RectangleF(posi3, new SizeF(_width, pump_block_height)); g.FillRectangle(gpBrush, rect3); } } } } #endregion } }