This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
CustomControl.cs
112 lines (94 loc) · 3.17 KB
/
CustomControl.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
namespace WindowsApplication1
{
public class CustomControl : Control, IToolTipControlClient
{
public CustomControl()
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
MyDrawControl(e);
}
private void MyDrawControl(PaintEventArgs e)
{
DrawBackGround(e);
DrawLine(e);
DrawStart(e);
DrawFinish(e);
}
private void DrawBackGround(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);
}
private void DrawLine(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(ForeColor), GetLineBounds(e.Graphics));
}
private void DrawStart(PaintEventArgs e)
{
Rectangle rect = GetStartBounds(e.Graphics);
e.Graphics.DrawString("Start", Font, new SolidBrush(ForeColor), rect);
}
private void DrawFinish(PaintEventArgs e)
{
Rectangle rect = GetFinishBounds(e.Graphics);
e.Graphics.DrawString("Finish", Font, new SolidBrush(ForeColor), rect);
}
private RectangleF GetLineBounds(Graphics e)
{
Rectangle rect1 = GetStartBounds(e);
Rectangle rect2 = GetFinishBounds(e);
int lineWidth = Width - rect1.Width - rect2.Width;
Rectangle rect = new Rectangle(rect1.Right, 0, lineWidth, Height);
return rect;
}
private Rectangle GetStartBounds(Graphics g)
{
Size size = g.MeasureString("Start", Font).ToSize();
return new Rectangle(0, 0, size.Width + 5, Height);
}
private Rectangle GetFinishBounds(Graphics g)
{
Size size = g.MeasureString("Finish", Font).ToSize();
return new Rectangle(Width - size.Width, 0, size.Width + 5, Height);
}
public string GetHintText(Point p)
{
Graphics graphics = CreateGraphics();
if (GetStartBounds(graphics).Contains(p))
return "Start";
if (GetFinishBounds(graphics).Contains(p))
return "Finish";
if (GetLineBounds(graphics).Contains(p))
return "Line";
return "Custom control";
}
#region IToolTipControlClient Members
ToolTipControlInfo IToolTipControlClient.GetObjectInfo(Point point)
{
string hintText = GetHintText(point);
ToolTipControlInfo info = new ToolTipControlInfo();
info.Object = hintText;
info.Text = hintText;
info.ToolTipPosition = Control.MousePosition;
info.Interval = 100;
info.Title = "Custom title";
info.ToolTipType = ToolTipType.SuperTip;
return info;
}
bool IToolTipControlClient.ShowToolTips
{
get { return true; }
}
#endregion
}
}