forked from TBSniller/cmpinf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusForm.cs
More file actions
101 lines (99 loc) · 2.94 KB
/
StatusForm.cs
File metadata and controls
101 lines (99 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
public class StatusForm : Form
{
private readonly ListBox logListBox;
private readonly CheckBox debugCheckBox;
private static StatusForm? instance;
public static StatusForm ShowSingleton()
{
if (instance == null || instance.IsDisposed)
{
instance = new StatusForm();
}
if (!instance.Visible)
{
instance.Show();
}
else
{
if (instance.WindowState == FormWindowState.Minimized)
instance.WindowState = FormWindowState.Normal;
instance.BringToFront();
instance.Activate();
FlashWindow(instance.Handle, true);
}
return instance;
}
[DllImport("user32.dll")]
private static extern bool FlashWindow(IntPtr hwnd, bool bInvert);
public StatusForm()
{
instance = this;
this.Text = "CmpInf - Logs";
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.StartPosition = FormStartPosition.CenterScreen;
this.ClientSize = new Size(500, 300);
this.TopMost = true;
var label = new Label
{
Text = "CmpInf - Replacement for SteelSeries System Monitor App (using LibreHardwareMonitorLib)",
AutoSize = false,
TextAlign = ContentAlignment.MiddleCenter,
Dock = DockStyle.Top,
Height = 32
};
debugCheckBox = new CheckBox
{
Text = "Enable Debug Logs",
Dock = DockStyle.Top,
Height = 24
};
debugCheckBox.CheckedChanged += (s, e) => {
Log.Verbose = debugCheckBox.Checked;
};
logListBox = new ListBox
{
Dock = DockStyle.Fill,
HorizontalScrollbar = true
};
this.Controls.Add(logListBox);
this.Controls.Add(debugCheckBox);
this.Controls.Add(label);
this.VisibleChanged += (s, e) =>
{
if (this.Visible)
{
Log.OnLog += AddLog;
}
else
{
Log.OnLog -= AddLog;
logListBox.Items.Clear();
}
};
this.FormClosing += (s, e) => {
// Hide instead of closing, so it can be reopened
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide();
}
};
}
private void AddLog(string level, string msg)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new Action(() => AddLog(level, msg)));
return;
}
if (level == "DEBUG" && !debugCheckBox.Checked) return;
logListBox.Items.Add(msg);
logListBox.TopIndex = logListBox.Items.Count - 1;
}
}