-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent app window showing on first run
1 parent
47fecd9
commit c63edc4
Showing
4 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace KFmaintenance.Services | ||
{ | ||
public class CustomApplicationContext : ApplicationContext | ||
{ | ||
/// <summary> | ||
/// The main application form. | ||
/// </summary> | ||
private Form _mainForm; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CustomApplicationContext"/> class. | ||
/// </summary> | ||
/// <param name="mainForm">The main form of the application.</param> | ||
public CustomApplicationContext(Form mainForm) | ||
{ | ||
_mainForm = mainForm; | ||
|
||
if (_mainForm != null) | ||
{ | ||
// Wire up the destroy events similar to how the base ApplicationContext | ||
// does things when a form is provided. | ||
_mainForm.HandleDestroyed += OnFormDestroy; | ||
|
||
// We still want to call Show() here, but we can at least hide it from the user | ||
// by setting Opacity to 0 while the form is being shown for the first time. | ||
_mainForm.Opacity = 0; | ||
_mainForm.Show(); | ||
_mainForm.Hide(); | ||
_mainForm.Opacity = 1; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Handles the <see cref="Control.HandleDestroyed"/> event. | ||
/// </summary> | ||
/// <param name="sender">The source of the event.</param> | ||
/// <param name="e">An <see cref="EventArgs"/> that contains the event data.</param> | ||
private void OnFormDestroy(object sender, EventArgs e) | ||
{ | ||
if (sender is Form form && !form.RecreatingHandle) | ||
{ | ||
form.HandleDestroyed -= OnFormDestroy; | ||
OnMainFormClosed(sender, e); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Performs application-defined tasks associated with freeing, releasing, | ||
/// or resetting unmanaged resources. | ||
/// </summary> | ||
/// <param name="disposing"> | ||
/// true if invoked from the <see cref="IDisposable.Dispose"/> method; | ||
/// false if invoked from the finalizer. | ||
/// </param> | ||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
if (_mainForm != null) | ||
{ | ||
if (!_mainForm.IsDisposed) | ||
{ | ||
_mainForm.Dispose(); | ||
} | ||
|
||
_mainForm = null; | ||
} | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,60 @@ | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace KFmaintenance.Services | ||
{ | ||
internal static class WindowsHelpers | ||
public static class WindowsHelpers | ||
{ | ||
public static void Shutdown() | ||
{ | ||
Process.Start("shutdown -s -t 0"); | ||
} | ||
|
||
public static void ApplyStyle(this DataGridView dgv) | ||
{ | ||
var font = new Font("Segoe UI", 9.87F, FontStyle.Regular, GraphicsUnit.Point, 0); | ||
|
||
// globals | ||
dgv.Font = font; | ||
dgv.BackColor = Color.FromArgb(45, 47, 49); | ||
dgv.ForeColor = Color.White; | ||
dgv.BorderStyle = BorderStyle.None; | ||
dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; | ||
|
||
// column header | ||
dgv.EnableHeadersVisualStyles = false; | ||
dgv.ColumnHeadersHeight = 50; | ||
dgv.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised; | ||
dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; | ||
|
||
// rows | ||
dgv.RowHeadersVisible = false; | ||
dgv.RowTemplate.Height = 25; | ||
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; | ||
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; | ||
dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; | ||
|
||
// cell style | ||
dgv.ColumnHeadersDefaultCellStyle = new DataGridViewCellStyle | ||
{ | ||
Font = font, | ||
ForeColor = Color.White, | ||
BackColor = Color.FromArgb(45, 47, 49), | ||
Alignment = DataGridViewContentAlignment.MiddleCenter | ||
}; | ||
|
||
dgv.DefaultCellStyle = new DataGridViewCellStyle | ||
{ | ||
BackColor = Color.FromArgb(60, 70, 73), | ||
SelectionBackColor = Color.FromArgb(35, 168, 109), | ||
SelectionForeColor = Color.White | ||
}; | ||
|
||
dgv.AlternatingRowsDefaultCellStyle = new DataGridViewCellStyle | ||
{ | ||
BackColor = Color.SlateGray | ||
}; | ||
} | ||
} | ||
} |