-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoundedTextBox.cs
More file actions
65 lines (57 loc) · 2.16 KB
/
RoundedTextBox.cs
File metadata and controls
65 lines (57 loc) · 2.16 KB
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
/* Author: Adam Dalibor Jurčík xjurci08
* David Zahálka xzahal03
*/
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculater
{
public class RoundedTextBox : TextBox
{
private int _borderRadius = 30;
public int BorderRadius
{
get { return _borderRadius; }
set { _borderRadius = value; this.Invalidate(); }
}
private GraphicsPath GetRoundPath(RectangleF Rect, int radius)
{
float r2 = radius / 2f;
GraphicsPath GraphPath = new GraphicsPath();
// Top left arc
GraphPath.AddArc(Rect.X, Rect.Y, radius, radius, 180, 90);
// Top border
GraphPath.AddLine(Rect.X + r2, Rect.Y, Rect.Width - r2, Rect.Y);
// Top right arc
GraphPath.AddArc(Rect.X + Rect.Width - radius, Rect.Y, radius, radius, 270, 90);
// Right border
GraphPath.AddLine(Rect.Width, Rect.Y + r2, Rect.Width, Rect.Height - r2);
// Bottom right arc
GraphPath.AddArc(Rect.X + Rect.Width - radius, Rect.Y + Rect.Height - radius, radius, radius, 0, 90);
// Bottom border
GraphPath.AddLine(Rect.Width - r2, Rect.Height, Rect.X + r2, Rect.Height);
// Bottom left arc
GraphPath.AddArc(Rect.X, Rect.Y + Rect.Height - radius, radius, radius, 90, 90);
// Left border
GraphPath.AddLine(Rect.X, Rect.Height - r2, Rect.X, Rect.Y + r2);
GraphPath.CloseFigure();
return GraphPath;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
RectangleF Rect = new RectangleF(0, 0, this.Width, this.Height);
GraphicsPath GraphPath = GetRoundPath(Rect, BorderRadius * 2);
this.Region = new Region(GraphPath);
using (Pen pen = new Pen(Color.Black, 1.75f))
{
e.Graphics.DrawPath(pen, GraphPath);
}
}
}
}