Skip to content

Commit 04e8a6e

Browse files
committed
Progress bars, minimise buttons and title label changes
- Progress bars added to encrypt and decrypt panels - Minimise buttons on the main form and dev form - Title label changes across all forms
1 parent 6928392 commit 04e8a6e

17 files changed

+471
-81
lines changed

FileAES/CustomControls/TextBoxWriter.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,6 @@ public override void WriteLine(string line)
4949

5050
private void AppendWithColour(string text)
5151
{
52-
/*
53-
if (text.Contains("DEBUG]"))
54-
{
55-
_output.SelectionStart = _output.TextLength;
56-
_output.SelectionLength = 0;
57-
_output.SelectionColor = Color.Violet;
58-
_output.AppendText(text.ToString());
59-
_output.SelectionColor = _output.ForeColor;
60-
}
61-
else if (text.Contains("WARN]"))
62-
{
63-
_output.SelectionStart = _output.TextLength;
64-
_output.SelectionLength = 0;
65-
_output.SelectionColor = Color.Yellow;
66-
_output.AppendText(text.ToString());
67-
_output.SelectionColor = _output.ForeColor;
68-
}
69-
else if (text.Contains("ERROR]"))
70-
{
71-
_output.SelectionStart = _output.TextLength;
72-
_output.SelectionLength = 0;
73-
_output.SelectionColor = Color.Red;
74-
_output.AppendText(text.ToString());
75-
_output.SelectionColor = _output.ForeColor;
76-
}
77-
else
78-
{
79-
_output.SelectionStart = _output.TextLength;
80-
_output.SelectionLength = 0;
81-
_output.SelectionColor = Color.LightGray;
82-
_output.AppendText(text.ToString());
83-
}*/
84-
8552
_output.SelectionColor = Color.LightGray;
8653
_output.AppendText(text.ToString());
8754
_output.AppendText(Environment.NewLine);
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Drawing;
4+
using System.Windows.Forms;
5+
6+
namespace FAES_GUI.CustomControls
7+
{
8+
public enum ProgressBarDisplayMode
9+
{
10+
NoText,
11+
Percentage,
12+
CurrProgress,
13+
CustomText,
14+
TextAndPercentage,
15+
TextAndCurrProgress
16+
}
17+
18+
public class TextProgressBar : ProgressBar
19+
{
20+
[Description("Font of the text on ProgressBar"), Category("Additional Options")]
21+
public Font TextFont { get; set; } = new Font(FontFamily.GenericSerif, 11, FontStyle.Bold | FontStyle.Italic);
22+
23+
private SolidBrush _textColourBrush = (SolidBrush)Brushes.Black;
24+
[Category("Additional Options")]
25+
public Color TextColor
26+
{
27+
get
28+
{
29+
return _textColourBrush.Color;
30+
}
31+
set
32+
{
33+
_textColourBrush.Dispose();
34+
_textColourBrush = new SolidBrush(value);
35+
}
36+
}
37+
38+
private SolidBrush _progressColourBrush = (SolidBrush)Brushes.LightGreen;
39+
[Category("Additional Options"), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
40+
public Color ProgressColor
41+
{
42+
get
43+
{
44+
return _progressColourBrush.Color;
45+
}
46+
set
47+
{
48+
_progressColourBrush.Dispose();
49+
_progressColourBrush = new SolidBrush(value);
50+
}
51+
}
52+
53+
private ProgressBarDisplayMode _visualMode = ProgressBarDisplayMode.CurrProgress;
54+
[Category("Additional Options"), Browsable(true)]
55+
public ProgressBarDisplayMode VisualMode
56+
{
57+
get
58+
{
59+
return _visualMode;
60+
}
61+
set
62+
{
63+
_visualMode = value;
64+
Invalidate();//redraw component after change value from VS Properties section
65+
}
66+
}
67+
68+
private string _text = string.Empty;
69+
70+
[Description("If it's empty, % will be shown"), Category("Additional Options"), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
71+
public string CustomText
72+
{
73+
get
74+
{
75+
return _text;
76+
}
77+
set
78+
{
79+
_text = value;
80+
Invalidate();//redraw component after change value from VS Properties section
81+
}
82+
}
83+
84+
private string _textToDraw
85+
{
86+
get
87+
{
88+
string text = CustomText;
89+
90+
switch (VisualMode)
91+
{
92+
case (ProgressBarDisplayMode.Percentage):
93+
text = _percentageStr;
94+
break;
95+
case (ProgressBarDisplayMode.CurrProgress):
96+
text = _currProgressStr;
97+
break;
98+
case (ProgressBarDisplayMode.TextAndCurrProgress):
99+
text = $"{CustomText}: {_currProgressStr}";
100+
break;
101+
case (ProgressBarDisplayMode.TextAndPercentage):
102+
text = $"{CustomText}: {_percentageStr}";
103+
break;
104+
}
105+
106+
return text;
107+
}
108+
set { }
109+
}
110+
111+
private string _percentageStr { get { return $"{(int)((float)Value - Minimum) / ((float)Maximum - Minimum) * 100 } %"; } }
112+
113+
private string _currProgressStr
114+
{
115+
get
116+
{
117+
return $"{Value}/{Maximum}";
118+
}
119+
}
120+
121+
public TextProgressBar()
122+
{
123+
Value = Minimum;
124+
FixComponentBlinking();
125+
}
126+
127+
private void FixComponentBlinking()
128+
{
129+
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
130+
}
131+
132+
protected override void OnPaint(PaintEventArgs e)
133+
{
134+
Graphics g = e.Graphics;
135+
136+
DrawProgressBar(g);
137+
138+
DrawStringIfNeeded(g);
139+
}
140+
141+
private void DrawProgressBar(Graphics g)
142+
{
143+
Rectangle rect = ClientRectangle;
144+
145+
ProgressBarRenderer.DrawHorizontalBar(g, rect);
146+
147+
rect.Inflate(-3, -3);
148+
149+
if (Value > 0)
150+
{
151+
Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
152+
153+
g.FillRectangle(_progressColourBrush, clip);
154+
}
155+
}
156+
157+
private void DrawStringIfNeeded(Graphics g)
158+
{
159+
if (VisualMode != ProgressBarDisplayMode.NoText)
160+
{
161+
162+
string text = _textToDraw;
163+
164+
SizeF len = g.MeasureString(text, TextFont);
165+
166+
Point location = new Point(((Width / 2) - (int)len.Width / 2), ((Height / 2) - (int)len.Height / 2));
167+
168+
g.DrawString(text, TextFont, (Brush)_textColourBrush, location);
169+
}
170+
}
171+
172+
public new void Dispose()
173+
{
174+
_textColourBrush.Dispose();
175+
_progressColourBrush.Dispose();
176+
base.Dispose();
177+
}
178+
}
179+
}

FileAES/DecryptForm.Designer.cs

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

FileAES/DecryptForm.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public DecryptForm(FAES_File faesFile)
1212
InitializeComponent();
1313

1414
titleLabel.Text += Program.GetVersion();
15+
this.Text = titleLabel.Text;
1516

1617
decryptPanel.LockFileSelect(true);
1718
decryptPanel.setCloseAfterOperationSuccessful(true);
@@ -20,7 +21,7 @@ public DecryptForm(FAES_File faesFile)
2021

2122
private void titleBar_Paint(object sender, PaintEventArgs e)
2223
{
23-
24+
ControlPaint.DrawBorder(e.Graphics, titleBar.ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
2425
}
2526

2627
private void titleBar_MouseDown(object sender, MouseEventArgs e)

FileAES/DevForm.Designer.cs

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

FileAES/DevForm.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public DevForm()
1313
InitializeComponent();
1414

1515
titleLabel.Text += Program.GetVersion();
16+
this.Text = titleLabel.Text;
17+
1618
Console.SetOut(new RichTextBoxWriter(consoleTextBox));
1719
}
1820

@@ -25,6 +27,11 @@ private void titleBar_MouseDown(object sender, MouseEventArgs e)
2527
}
2628
}
2729

30+
private void titleBar_Paint(object sender, PaintEventArgs e)
31+
{
32+
ControlPaint.DrawBorder(e.Graphics, titleBar.ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
33+
}
34+
2835
protected override void OnPaint(PaintEventArgs e)
2936
{
3037
ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
@@ -55,11 +62,33 @@ private void quitButton_MouseHover(object sender, EventArgs e)
5562
slowToolTip.SetToolTip(quitButton, "Close");
5663
}
5764

58-
private void QuitButton_Click(object sender, EventArgs e)
65+
private void minButton_MouseEnter(object sender, EventArgs e)
66+
{
67+
minButton.BackColor = Color.LightGray;
68+
minButton.ForeColor = Color.White;
69+
}
70+
71+
private void minButton_MouseLeave(object sender, EventArgs e)
72+
{
73+
minButton.BackColor = Color.Transparent;
74+
minButton.ForeColor = Color.White;
75+
}
76+
77+
private void minButton_MouseHover(object sender, EventArgs e)
78+
{
79+
slowToolTip.SetToolTip(minButton, "Minimise");
80+
}
81+
82+
private void quitButton_Click(object sender, EventArgs e)
5983
{
6084
Hide();
6185
}
6286

87+
private void minButton_Click(object sender, EventArgs e)
88+
{
89+
this.WindowState = FormWindowState.Minimized;
90+
}
91+
6392
protected override void OnFormClosing(FormClosingEventArgs e)
6493
{
6594
if (e.CloseReason == CloseReason.UserClosing)

0 commit comments

Comments
 (0)