-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugForm.cs
More file actions
79 lines (68 loc) · 1.78 KB
/
Copy pathDebugForm.cs
File metadata and controls
79 lines (68 loc) · 1.78 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
using System.Drawing;
using System.Windows.Forms;
namespace LinuxWindowDrag;
internal sealed class DebugForm : Form
{
private readonly TextBox _debugText;
private readonly Queue<string> _messageQueue;
private const int MaxMessages = 1000;
internal DebugForm()
{
_messageQueue = new Queue<string>();
Text = "Linux Window Drag - Debug";
Size = new Size(600, 400);
StartPosition = FormStartPosition.CenterScreen;
TopMost = true;
_debugText = new TextBox
{
Multiline = true,
ReadOnly = true,
Dock = DockStyle.Fill,
Font = new Font("Courier New", 9),
BackColor = Color.Black,
ForeColor = Color.LimeGreen,
WordWrap = false,
ScrollBars = ScrollBars.Vertical,
};
Controls.Add(_debugText);
Log("Debug window started");
}
internal void Log(string message)
{
_messageQueue.Enqueue($"[{DateTime.Now:HH:mm:ss.fff}] {message}");
if (_messageQueue.Count > MaxMessages)
{
_messageQueue.Dequeue();
}
if (InvokeRequired)
{
BeginInvoke(UpdateDisplay);
}
else
{
UpdateDisplay();
}
}
internal void ClearLog()
{
if (InvokeRequired)
{
BeginInvoke(ClearLogInternal);
}
else
{
ClearLogInternal();
}
}
private void ClearLogInternal()
{
_messageQueue.Clear();
_debugText.Clear();
}
private void UpdateDisplay()
{
_debugText.Text = string.Join(Environment.NewLine, _messageQueue);
_debugText.SelectionStart = _debugText.Text.Length;
_debugText.ScrollToCaret();
}
}