Skip to content

Commit

Permalink
Adding: New GUI (Custom Form & Controls)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambratolm authored and Ambratolm committed Jun 9, 2021
1 parent 0e70196 commit 2f355da
Show file tree
Hide file tree
Showing 44 changed files with 2,562 additions and 342 deletions.
19 changes: 19 additions & 0 deletions Ping Tester Aluminium/API/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using PingTesterAluminium.Properties;

namespace PingTesterAluminium
{
public static class Constants
{
public static FontFamily VisitorFontFamily { get; private set; }

static Constants()
{
Constants.VisitorFontFamily = Resources.visitor.ToFontFamily();
}
}
}
30 changes: 30 additions & 0 deletions Ping Tester Aluminium/API/Extensions/ButtonExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace PingTesterAluminium
{
public static class ButtonExtension
{
public static void EnableHoverEffects(this Button button)
{
Image backgroundImage = button.BackgroundImage;
Color backColor = button.BackColor;

button.MouseEnter += (s, e) =>
{
button.BackgroundImage = null;
button.BackColor = Color.FromArgb(230, 230, 230);
};

button.MouseLeave += (s, e) =>
{
button.BackgroundImage = backgroundImage;
button.BackColor = backColor;
};
}
}
}
15 changes: 15 additions & 0 deletions Ping Tester Aluminium/API/Extensions/ControlExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,20 @@ public static void CenterHorizontally(this Control control)
control.Location = new Point((int)(0.5 * control.Parent.Width - 0.5 * control.Width), control.Location.Y);
}
}

public static void EnableHoverEffectsForChildButtons(this Control control)
{
foreach (Control childControl in control.Controls)
{
if (childControl is Button)
{
(childControl as Button).EnableHoverEffects();
}
else if (childControl.HasChildren)
{
childControl.EnableHoverEffectsForChildButtons();
}
}
}
}
}
22 changes: 1 addition & 21 deletions Ping Tester Aluminium/API/Extensions/FormExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@ namespace PingTesterAluminium
{
public static class FormExtension
{
public static void EnableButtonsHoverEffects(this Form form)
{
foreach (Control control in form.Controls)
{
if (control is Button)
{
Button button = (Button)control;
Image backgroundImage = button.BackgroundImage;

button.MouseEnter += (s, args) =>
{
button.BackgroundImage = null;
};

button.MouseLeave += (s, args) =>
{
button.BackgroundImage = backgroundImage;
};
}
}
}

}
}
16 changes: 16 additions & 0 deletions Ping Tester Aluminium/API/Extensions/ImageExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace PingTesterAluminium
{
public static class ImageExtension
{
public static Icon ToIcon(this Image image)
{
return Icon.FromHandle(((Bitmap)image).GetHicon());
}
}
}
300 changes: 300 additions & 0 deletions Ping Tester Aluminium/Form1.Designer.cs

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions Ping Tester Aluminium/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PingTesterAluminium.Properties;

namespace PingTesterAluminium
{
public partial class Form1 : AluminiumForm
{
public int Counter { get; set; }
public List<ProgressBar> ProgressBars { get; set; }

public Form1()
{
InitializeComponent();
ProgressBars = new List<ProgressBar>();
foreach (Control control in panel_time.Controls)
{
if (control is ProgressBar)
{
ProgressBars.Add(control as ProgressBar);
}
}
timer_main.Start();
}

public void IncrementCounter()
{
if (Counter < ProgressBars.Count - 1)
{
Counter++;
}
else
{
Counter = 0;
}
}

public void UpdateProgressBar(ProgressBar progressBar, PingResult response)
{
if (response.Time > progressBar.Maximum)
{
progressBar.Value = progressBar.Maximum;
}
else if (response.Time < progressBar.Minimum)
{
progressBar.Value = progressBar.Minimum;
}
else
{
progressBar.Value = (int)response.Time;
}
progressBar.ForeColor = response.Color;
}

public void UpdateProgressBar(PingResult response)
{
UpdateProgressBar(ProgressBars[Counter], response);
IncrementCounter();
}

private void timer_main_Tick(object sender, EventArgs e)
{
if (Settings.Default.Interval < 1000)
{
timer_main.Interval = 1000;
}
else
{
timer_main.Interval = Settings.Default.Interval;
}

if (timer_main.Interval != Settings.Default.Interval)
{
Settings.Default.Interval = timer_main.Interval;
Settings.Default.Save();
}

if (!backgroundWorker_main.IsBusy)
{
backgroundWorker_main.RunWorkerAsync(Settings.Default.Host);
}
}

private void backgroundWorker_main_DoWork(object sender, DoWorkEventArgs e)
{
e.Result = PingTest.Ping(e.Argument as string);
}

private void backgroundWorker_main_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
PingResult response = e.Result as PingResult;

label_time.Text = response.Time > 0 ? response.Time.ToString() + " ms" : "Timeout";
label_time.ForeColor = response.Color;

UpdateProgressBar(response);

label_rating.Text = response.Rating;
label_rating.ForeColor = response.Color;

label_host.Text = response.Host;

if (response.Host != Settings.Default.Host)
{
Settings.Default.Host = response.Host;
Settings.Default.Save();
}
}

private void button_play_Click(object sender, EventArgs e)
{

}
}
}
Loading

0 comments on commit 2f355da

Please sign in to comment.