Skip to content

Commit

Permalink
Two new options, min. to taskbar + topmost. reduce form flicker.
Browse files Browse the repository at this point in the history
  • Loading branch information
voltura committed Nov 22, 2022
1 parent c578438 commit 0d23d68
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 163 deletions.
11 changes: 11 additions & 0 deletions EarnerApp/Forms/AboutForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public AboutForm()

#region Private methods

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}


private void LoadAppSettings()
{
_Settings.Load();
Expand Down
11 changes: 11 additions & 0 deletions EarnerApp/Forms/ConfirmForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ private void SetTooltips()

#region Private events

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}


private void YesClick(object sender, EventArgs e)
{
Log.LogCaller();
Expand Down
1 change: 0 additions & 1 deletion EarnerApp/Forms/EarnerForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 72 additions & 1 deletion EarnerApp/Forms/EarnerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public partial class EarnerForm : Form

private string _InternetVersion = string.Empty;

private readonly NotifyIcon _NotifyIcon;

#endregion Private variables

#region Constructor
Expand All @@ -46,7 +48,15 @@ public EarnerForm()
_EarnerRecords = EarnerRecords.Instance;
InitializeComponent();
_lblEarnerHeader.Text = $"{Application.ProductName} {Application.ProductVersion}";
_NotifyIcon = new()
{
Icon = Resources.dollar,
Visible = _Settings.MinimizeToTaskbar
};
_NotifyIcon.Click += NotifyIconClick;
_NotifyIcon.MouseClick += NotifyIconClick;
LoadAppSettings();
ShowInTaskbar = !_Settings.MinimizeToTaskbar;
StartEarning();
}

Expand All @@ -61,6 +71,8 @@ private void LoadAppSettings()
_ActiveTask = _Settings.Tasks.FirstOrDefault("Default Task");
_lblActiveTask.Text = $"Working with {_ActiveTask}";
_pbWorkProgress.Visible = _Settings.ShowProgressbar;
TopMost = _Settings.StayOnTop;
_NotifyIcon.Visible = _Settings.MinimizeToTaskbar;
}

private void SetTooltips()
Expand Down Expand Up @@ -111,6 +123,7 @@ private void StartEarning()
}
finally
{
ShowInTaskbar = !_Settings.MinimizeToTaskbar;
Visible = true;
}
}
Expand Down Expand Up @@ -334,6 +347,7 @@ private void OptionsClick(object sender, EventArgs e)
}
finally
{
ShowInTaskbar = !_Settings.MinimizeToTaskbar;
Visible = true;
}
if (sfDialogResult == DialogResult.OK)
Expand Down Expand Up @@ -382,6 +396,16 @@ private void Tick(object sender, EventArgs e)
}
}

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}

private void HideClick(object sender, EventArgs e)
{
if (_btnHide.Tag != null && _btnHide.Tag.ToString() == "Update")
Expand All @@ -393,7 +417,40 @@ private void HideClick(object sender, EventArgs e)
}

_DoNotChangeFontSize = true;
WindowState = FormWindowState.Minimized;
if (WindowState != FormWindowState.Minimized)
{
WindowState = FormWindowState.Minimized;
}

if (_Settings.MinimizeToTaskbar)
{
if (Visible)
{
Hide();
}

if (!_NotifyIcon.Visible)
{
_NotifyIcon.Visible = true;
}
}
else
{
if (!Visible)
{
Visible = true;
}

if (_NotifyIcon.Visible)
{
_NotifyIcon.Visible = false;
}

if (!ShowInTaskbar)
{
ShowInTaskbar = true;
}
}
}

private void TopPanelMouseDown(object sender, MouseEventArgs e)
Expand Down Expand Up @@ -491,6 +548,12 @@ private void ScaleTextChanged(object sender, EventArgs e)
private void EarnerFormResize(object sender, EventArgs e)
{
_DoNotChangeFontSize = WindowState == FormWindowState.Minimized;
if (WindowState == FormWindowState.Minimized && _NotifyIcon is not null)
{
ShowInTaskbar = false;
_NotifyIcon.Visible = true;
Visible = false;
}
}

private void EarnerFormKeyDown(object sender, KeyEventArgs e)
Expand Down Expand Up @@ -546,6 +609,14 @@ private void EarnerFormShown(object sender, EventArgs e)
GetAndDisplayUpdateInfoInHeader();
}

private void NotifyIconClick(object? sender, EventArgs e)
{
WindowState = FormWindowState.Normal;
Show();
_ = Focus();
ShowInTaskbar = !_Settings.MinimizeToTaskbar;
}

#endregion Private events
}
}
31 changes: 21 additions & 10 deletions EarnerApp/Forms/LogAdminForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ private void PopulateDatagrid()

#region Private methods

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}


private void SetTooltips()
{
if (_Settings.ShowTooltips)
Expand All @@ -83,6 +94,16 @@ private void SetTooltips()
}
}

private void EarnerRecordsDefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells[0].Value = $"Task_{DateTime.Now.Ticks.ToString()[10..]}";
e.Row.Cells[1].Value = "0";
e.Row.Cells[2].Value = DateTime.Now.ToString("yyyy-MM-dd");
e.Row.Cells[3].Value = "0";
e.Row.Cells[4].Value = _Settings.CurrencySymbol;
e.Row.Cells[5].Value = Math.Round(_Settings.HourlyRate, 2, MidpointRounding.AwayFromZero).ToString();
}

#endregion Private methods

#region Private events
Expand Down Expand Up @@ -309,15 +330,5 @@ private void EarnerRecordsCellValidating(object sender, DataGridViewCellValidati
}

#endregion Private events

private void EarnerRecordsDefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells[0].Value = $"Task_{DateTime.Now.Ticks.ToString()[10..]}";
e.Row.Cells[1].Value = "0";
e.Row.Cells[2].Value = DateTime.Now.ToString("yyyy-MM-dd");
e.Row.Cells[3].Value = "0";
e.Row.Cells[4].Value = _Settings.CurrencySymbol;
e.Row.Cells[5].Value = Math.Round(_Settings.HourlyRate, 2, MidpointRounding.AwayFromZero).ToString();
}
}
}
10 changes: 10 additions & 0 deletions EarnerApp/Forms/LogPeriodForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public LogPeriodForm()

#region Private methods

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}

private void LoadAppSettings()
{
_Settings.Load();
Expand Down
Loading

0 comments on commit 0d23d68

Please sign in to comment.