Skip to content

Commit 8df9186

Browse files
author
itzkxhu
committed
allow to modify each rounded corner's diameter in some controls
1 parent ffd7eb8 commit 8df9186

10 files changed

+294
-82
lines changed

wfcl1/Controls/Forms/ComboBoxDropDown.Designer.cs

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace CuoreUI.Controls.Forms
12+
{
13+
public partial class ComboBoxDropDown : Form
14+
{
15+
private string[] privateItems = new string[] { "" };
16+
public string[] Items
17+
{
18+
get
19+
{
20+
return privateItems;
21+
}
22+
set
23+
{
24+
privateItems = value;
25+
Invalidate();
26+
}
27+
}
28+
public ComboBoxDropDown()
29+
{
30+
InitializeComponent();
31+
}
32+
33+
protected override void OnPaint(PaintEventArgs e)
34+
{
35+
base.OnPaint(e);
36+
37+
int i = 0;
38+
int firstItem = 0;
39+
int lastItem = Items.Length - 1;
40+
foreach (var item in Items)
41+
{
42+
if (i == firstItem)
43+
{
44+
45+
}
46+
i++;
47+
}
48+
}
49+
}
50+
}

wfcl1/Controls/cuiBorder.Designer.cs

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wfcl1/Controls/cuiBorder.cs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System;
2-
using System.Drawing;
1+
using System.Drawing;
32
using System.Drawing.Drawing2D;
43
using System.Windows.Forms;
54

65
namespace CuoreUI.Controls
76
{
8-
public partial class cuiBorder : UserControl
7+
public partial class cuiBorder : Control
98
{
109
private Color privatePanelColor = Color.MediumSlateBlue;
1110
public Color PanelColor
@@ -25,51 +24,36 @@ public cuiBorder()
2524
{
2625
InitializeComponent();
2726
DoubleBuffered = true;
28-
AutoScaleMode = AutoScaleMode.None;
2927
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
3028
}
3129

3230

33-
private int privateRounding = 8;
34-
public int Rounding
31+
private Padding privateRounding = new Padding(8, 8, 8, 8);
32+
public Padding Rounding
3533
{
3634
get
3735
{
3836
return privateRounding;
3937
}
4038
set
4139
{
42-
if (value > 0)
43-
{
44-
if (value > (ClientRectangle.Height / 2))
45-
{
46-
privateRounding = ClientRectangle.Height / 2;
47-
Rounding = privateRounding;
48-
}
49-
else
50-
{
51-
privateRounding = value;
52-
}
53-
}
54-
else
55-
{
56-
throw new Exception("Rounding cannot be less than 1");
57-
}
40+
privateRounding = value;
5841
Invalidate();
5942
}
6043
}
6144

6245
protected override void OnPaint(PaintEventArgs e)
6346
{
47+
base.OnPaint(e);
6448
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
49+
Rectangle modifiedCR = ClientRectangle;
50+
modifiedCR.Inflate(-1, -1);
6551

66-
GraphicsPath roundBackground = Helper.RoundRect(ClientRectangle, Rounding);
52+
GraphicsPath roundBackground = Helper.RoundRect(modifiedCR, Rounding);
6753
using (SolidBrush brush = new SolidBrush(PanelColor))
6854
{
6955
e.Graphics.FillPath(brush, roundBackground);
7056
}
71-
base.OnPaint(e);
72-
7357
}
7458
}
7559
}

wfcl1/Controls/cuiButton.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,16 @@ public string Content
3232
}
3333
}
3434

35-
private int privateRounding = 8;
36-
public int Rounding
35+
private Padding privateRounding = new Padding(8, 8, 8, 8);
36+
public Padding Rounding
3737
{
3838
get
3939
{
4040
return privateRounding;
4141
}
4242
set
4343
{
44-
if (value > 0)
45-
{
46-
if (value > (ClientRectangle.Height / 2))
47-
{
48-
privateRounding = ClientRectangle.Height / 2;
49-
Rounding = privateRounding;
50-
}
51-
else
52-
{
53-
privateRounding = value;
54-
}
55-
}
56-
else
57-
{
58-
throw new Exception("Rounding cannot be less than 1");
59-
}
44+
privateRounding = value;
6045
Invalidate();
6146
}
6247
}
@@ -169,8 +154,10 @@ protected override void OnPaint(PaintEventArgs e)
169154
stringFormat.Alignment = StringAlignment.Center;
170155
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
171156
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
157+
Rectangle modifiedCR = ClientRectangle;
158+
modifiedCR.Inflate(-1, -1);
172159

173-
GraphicsPath roundBackground = Helper.RoundRect(ClientRectangle, Rounding);
160+
GraphicsPath roundBackground = Helper.RoundRect(modifiedCR, Rounding);
174161

175162
Color renderedBackgroundColor;
176163
Color renderedOutlineColor;

wfcl1/Controls/cuiProgressBarHorizontal.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,14 @@ public int Rounding
9595
}
9696
set
9797
{
98-
if (value > 0)
98+
if (value > (ClientRectangle.Height / 2))
9999
{
100-
if (value > (ClientRectangle.Height / 2))
101-
{
102-
privateRounding = ClientRectangle.Height / 2;
103-
Rounding = privateRounding;
104-
}
105-
else
106-
{
107-
privateRounding = value;
108-
}
100+
privateRounding = ClientRectangle.Height / 2;
101+
Rounding = privateRounding;
109102
}
110103
else
111104
{
112-
throw new Exception("Rounding cannot be less than 1");
105+
privateRounding = value;
113106
}
114107
Invalidate();
115108
}

wfcl1/Controls/cuiStarRating.cs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public cuiStarRating()
2525
private Color privateStarColor = Color.MediumSlateBlue;
2626
private int privateStarBorderSize = 1;
2727

28-
// Public properties to access private variables
29-
3028
public int StarCount
3129
{
3230
get
@@ -36,6 +34,7 @@ public int StarCount
3634
set
3735
{
3836
privateStarCount = value;
37+
Invalidate();
3938
}
4039
}
4140

@@ -48,6 +47,7 @@ public int Rating
4847
set
4948
{
5049
privateRating = value;
50+
Invalidate();
5151
}
5252
}
5353

@@ -60,6 +60,7 @@ public Color StarColor
6060
set
6161
{
6262
privateStarColor = value;
63+
Invalidate();
6364
}
6465
}
6566

@@ -72,8 +73,24 @@ public int StarBorderSize
7273
set
7374
{
7475
privateStarBorderSize = value;
76+
Invalidate();
7577
}
7678
}
79+
80+
private bool privateAllowUserInteraction = true;
81+
public bool AllowUserInteraction
82+
{
83+
get
84+
{
85+
return privateAllowUserInteraction;
86+
}
87+
set
88+
{
89+
privateAllowUserInteraction = value;
90+
Invalidate();
91+
}
92+
}
93+
7794
protected override void OnPaint(PaintEventArgs e)
7895
{
7996
base.OnPaint(e);
@@ -89,7 +106,10 @@ protected override void OnPaint(PaintEventArgs e)
89106
int starLeft = i * (starWidth + spacing);
90107
Rectangle starRect = new Rectangle(starLeft, 0, starWidth, this.Height);
91108
starRect.Offset(starWidth / 2, 0);
92-
GraphicsPath starPath = Helper.Star(starLeft + starWidth / 2, this.Height / 2, starWidth / 2, starWidth / 3.8f, 5);
109+
starRect.Inflate(-StarBorderSize, -StarBorderSize);
110+
starRect.Offset(StarBorderSize / 2, StarBorderSize / 2);
111+
112+
GraphicsPath starPath = Helper.Star(starLeft + starWidth / 2, Height / 2, starWidth / 2, starWidth / 3.8f, 5);
93113

94114
if ((i + 1) * 2 <= Rating)
95115
{
@@ -98,14 +118,65 @@ protected override void OnPaint(PaintEventArgs e)
98118
else if (i * 2 + 1 == Rating)
99119
{
100120
e.Graphics.FillPath(new SolidBrush(StarColor), starPath);
121+
122+
starRect.Inflate(StarBorderSize, StarBorderSize);
123+
starRect.Offset(-(StarBorderSize / 2), -(StarBorderSize / 2));
101124
e.Graphics.FillRectangle(new SolidBrush(BackColor), starRect);
102125
}
103126

104-
using (Pen starBorderPen = new Pen(StarColor, StarBorderSize))
127+
using (Pen starBorderPen = new Pen(StarColor, (float)StarBorderSize / 2f))
105128
{
106129
e.Graphics.DrawPath(starBorderPen, starPath);
107130
}
108131
}
109132
}
133+
134+
protected override void OnMouseMove(MouseEventArgs e)
135+
{
136+
base.OnMouseMove(e);
137+
138+
if (AllowUserInteraction == false)
139+
{
140+
return;
141+
}
142+
143+
if (e.Button == MouseButtons.Left)
144+
{
145+
int starWidth = Height - 2;
146+
int spacing = starWidth / 5;
147+
int starCount = 5;
148+
149+
int mouseX = e.X + 5;
150+
151+
if (mouseX < 0)
152+
{
153+
Rating = 0;
154+
}
155+
else if (mouseX > starCount * (starWidth + spacing))
156+
{
157+
Rating = 10;
158+
}
159+
else
160+
{
161+
int starClicked = (mouseX - spacing) / ((int)starWidth + spacing);
162+
float remainder = (mouseX - spacing) % (starWidth + spacing);
163+
164+
if (remainder > starWidth / 2)
165+
{
166+
Rating = (starClicked + 1) * 2;
167+
}
168+
else
169+
{
170+
Rating = starClicked * 2 + 1;
171+
}
172+
}
173+
}
174+
}
175+
176+
protected override void OnMouseDown(MouseEventArgs e)
177+
{
178+
base.OnMouseDown(e);
179+
OnMouseMove(e);
180+
}
110181
}
111182
}

0 commit comments

Comments
 (0)