|
using DevExpress.Utils.Extensions;
|
using DevExpress.XtraCharts.Native;
|
using Eventech.Utils.Images;
|
using System;
|
using System.ComponentModel.DataAnnotations;
|
using System.Drawing;
|
|
namespace IStation.WinFrmUI
|
{
|
|
public class HourSmallBlock
|
{
|
|
|
#region 变量
|
/// <summary>
|
/// 是否是边界的盒子
|
/// </summary>
|
public bool IsLineStartBlck { get; set; } = false;
|
public bool IsLineEndBlck { get; set; } = false;
|
/// <summary>
|
/// 下标
|
/// </summary>
|
public int Hour
|
{
|
get { return _hour; }
|
}
|
private int _hour;
|
|
/// <summary>
|
/// 是否可选
|
/// </summary>
|
public bool IsSelectedAble { get; set; } = true;
|
|
|
/// <summary>
|
/// 矩形左上角坐标
|
/// </summary>
|
public Point LocPoint { get { return _loc_point; } }
|
private Point _loc_point;
|
|
private Point _text_point;
|
|
private int _width = 35;
|
public int Width { get { return _width; } }
|
|
private int _height = 25;
|
public int Height { get { return _height; } }
|
|
/// <summary>
|
/// 矩形
|
/// </summary>
|
public RectangleF Rectangle
|
{
|
get { return _rect; }
|
}
|
private RectangleF _rect;
|
|
/// <summary>
|
/// 边框宽度
|
/// </summary>
|
public int BorderWidth
|
{
|
get => _borderWidth;
|
}
|
private int _borderWidth = 1;
|
|
/// <summary>
|
/// 默认颜色
|
/// </summary>
|
public Color DefaultColor
|
{
|
get => _defaultColor;
|
set => _defaultColor = value;
|
}
|
private Color _defaultColor = Color.White;
|
|
|
|
|
|
/// <summary>
|
/// 边框色
|
/// </summary>
|
public Color BorderColor
|
{
|
get => _borderColor;
|
}
|
private Color _borderColor = Color.Black;
|
|
/// <summary>
|
/// 字体色
|
/// </summary>
|
public Color FontColor
|
{
|
get => _fontColor;
|
}
|
private Color _fontColor = Color.Black;
|
|
/// <summary>
|
/// 选中状态
|
/// </summary>
|
public bool IsSelected
|
{
|
get => _selected;
|
set
|
{
|
_selected = value;
|
}
|
}
|
private bool _selected = false;
|
|
|
/// <summary>
|
/// 文本信息
|
/// </summary>
|
public string TextContent
|
{
|
get => _textContent;
|
set => _textContent = value;
|
}
|
private string _textContent;
|
|
/// <summary>
|
/// 文本可见性
|
/// </summary>
|
public bool TextVisible
|
{
|
get => _textVisible;
|
set => _textVisible = value;
|
}
|
private bool _textVisible = false;
|
|
|
public double Mark { get; set; } = -1;
|
|
#endregion
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="hour"></param>
|
/// <param name="time"></param>
|
public HourSmallBlock(int hour)
|
{
|
this._hour = hour;
|
if (hour % 2 == 0)
|
{
|
this._textContent = hour.ToString();
|
this._textVisible = true;
|
this._text_point = new Point(10, 10);
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
/// 调整大小
|
/// </summary>
|
public void Resize(int x, int y)
|
{
|
_loc_point = new Point(x, y);
|
_text_point = new Point(x + 10, y+5);
|
_rect = new Rectangle(_loc_point, new Size(_width, _height));
|
}
|
|
|
/// <summary>
|
/// 绘制
|
/// </summary>
|
public void Draw(Graphics g)
|
{
|
Color drawColor = _defaultColor;
|
|
|
//if (drawColor == _currentBlockColor)
|
// return;
|
using (Pen dashpen = new Pen(Color.Red, 1))
|
using (Brush gpBrush = new SolidBrush(drawColor))
|
using (var pen = new Pen(_borderColor, _borderWidth))
|
{
|
dashpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
|
dashpen.DashPattern = new float[] { 2, 2 };
|
|
//g.DrawRectangle(pen, _rect);
|
g.DrawLine(pen, _rect.LeftTop(), _rect.RightTop());
|
g.DrawLine(pen, _rect.LeftBottom(), _rect.RightBottom());
|
|
|
if (IsLineStartBlck)
|
{
|
g.DrawLine(pen, _rect.LeftTop(), _rect.LeftBottom());
|
}
|
else
|
{
|
g.DrawLine(dashpen, _rect.LeftTop(), _rect.LeftBottom());
|
}
|
|
if (IsLineEndBlck)
|
{
|
g.DrawLine(pen, _rect.RightTop(), _rect.RightBottom());
|
}
|
|
g.FillRectangle(gpBrush, _rect);
|
|
DrawTimeTxt(g);
|
|
if (Mark > 0)
|
{
|
DrawMarkTxt(g);
|
}
|
|
if (!IsSelectedAble)
|
{
|
g.DrawLine(pen, _loc_point, new PointF(_rect.Right, _rect.Bottom));
|
}
|
}
|
|
|
|
|
}
|
|
|
/// <summary>
|
/// 绘制文本
|
/// </summary>
|
private void DrawMarkTxt(Graphics g)
|
{
|
if (Mark <= 0)
|
return;
|
using (var font = new Font("微软雅黑", 6))//字体
|
using (var brush = new SolidBrush(Color.Red))//笔刷
|
{
|
var format = new StringFormat();//文本格式
|
format.LineAlignment = StringAlignment.Near;//垂直居中
|
format.Alignment = StringAlignment.Center;//水平居中
|
var point = new Point(_loc_point.X + this.Width - 7 , _loc_point.Y+2);
|
//var scaleFont = ScaleFont(g, txt, _rect.Size, font);//缩放后字体
|
//g.DrawString(txt, font, brush, _rect, format);//绘制文本(文本,字体,笔刷,矩形,文本格式)
|
g.DrawString(Mark.ToString(), font, brush, point);
|
}
|
}
|
|
|
/// <summary>
|
/// 绘制文本
|
/// </summary>
|
private void DrawTimeTxt(Graphics g )
|
{
|
if (!_textVisible || string.IsNullOrEmpty(_textContent))
|
return;
|
using (var font = new Font("微软雅黑", 7, FontStyle.Bold))//字体
|
using (var brush = new SolidBrush(_fontColor))//笔刷
|
{
|
//var format = new StringFormat();//文本格式
|
//format.LineAlignment = StringAlignment.Center;//垂直居中
|
//format.Alignment = StringAlignment.Center;//水平居中
|
|
//var scaleFont = ScaleFont(g, txt, _rect.Size, font);//缩放后字体
|
//g.DrawString(txt, font, brush, _rect, format);//绘制文本(文本,字体,笔刷,矩形,文本格式)
|
g.DrawString(_textContent, font, brush, _text_point);
|
}
|
}
|
|
/// <summary>
|
/// 缩放后字体
|
/// </summary>
|
private Font ScaleFont(Graphics g, string longString, Size Rec, Font PreferedFont)//画布,文本,矩形,字体
|
{
|
SizeF RealSize = g.MeasureString(longString, PreferedFont);//文本大小
|
float HeightScaleRatio = Rec.Height / RealSize.Height;//高度缩放比例
|
float WidthScaleRatio = Rec.Width / RealSize.Width;//宽度缩放比例
|
float ScaleRatio = (HeightScaleRatio < WidthScaleRatio) ? ScaleRatio = HeightScaleRatio : ScaleRatio = WidthScaleRatio;//按高度缩放||按宽度缩放
|
float ScaleFontSize = PreferedFont.Size * ScaleRatio;//缩放后的字体大小
|
return new Font(PreferedFont.FontFamily, ScaleFontSize);
|
}
|
|
|
/// <summary>
|
/// 包含点
|
/// </summary>
|
public bool ContainsPoint(Point point)
|
{
|
return _rect.Contains(point);
|
}
|
|
|
|
|
}
|
}
|