tangxu
2024-03-26 edd23f115dba31d764fdaf75a6207d888d0419d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
 
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);
        }
 
 
 
 
    }
}