-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cs
186 lines (151 loc) · 6.07 KB
/
Settings.cs
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using BlueMystic;
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using static BlueMystic.DarkModeCS;
namespace SettingsWindow
{
public partial class Settings : Form
{
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int dwAttribute, ref int pvAttribute, int cbAttribute);
public Settings()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
Icon = PingTester.Properties.Resources.Perfect;
this.MinimizeBox = true; // Habilita el botón de minimizar
this.MaximizeBox = false; // Deshabilita el botón de maximizar
// Set the window corner preference for the context menu strip
var contextMenuStrip = new ContextMenuStrip();
var attribute = DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE;
var preference = (int)DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND;
DwmSetWindowAttribute(contextMenuStrip.Handle, (int)attribute, ref preference, sizeof(int));
Console.SetOut(new ControlWriter(consoleOutput));
SetTitleBarColor();
}
private void Settings_Load(object sender, EventArgs e)
{
// Read the settings from the registry
var settings = PingTester.Program.ReadSettings();
this.BackColor = ColorTranslator.FromHtml("#242424");
// Populate the textboxes with the settings values
pingCountTextBox.Text = settings.PingCount.ToString();
secondsBetweenPingsTextBox.Text = settings.SecondsBetweenPings.ToString();
maxResponseTimeTextBox.Text = settings.MaxResponseTime.ToString();
serverToPingTextBox.Text = settings.ServerToPing;
perfectThresholdTextBox.Text = settings.PerfectThreshold.ToString();
goodThresholdTextBox.Text = settings.GoodThreshold.ToString();
mediumThresholdTextBox.Text = settings.MediumThreshold.ToString();
}
private void SetTitleBarColor()
{
// Define el atributo DWMWA_CAPTION_COLOR
const int DWMWA_CAPTION_COLOR = 35;
// Define el color que deseas para la barra de título (Negro en este caso)
int color = 0x202020; // Color negro en formato BGR
// Configura el atributo de la ventana
DwmSetWindowAttribute(this.Handle, DWMWA_CAPTION_COLOR, ref color, sizeof(int));
}
private void TogglePanelsButton_Click(object sender, EventArgs e)
{
settingsPanel.Visible = !settingsPanel.Visible;
additionalPanel.Visible = !additionalPanel.Visible;
if (this.togglePanelsButton.Text.Equals("Show console"))
{
this.togglePanelsButton.Text = "Show parameters";
}
else if (this.togglePanelsButton.Text.Equals("Show parameters"))
{
this.togglePanelsButton.Text = "Show console";
return;
}
}
private void SaveButton_Click(object sender, EventArgs e)
{
// Create a new Settings object with the updated values
var settings = new PingTester.Settings
{
PingCount = int.Parse(pingCountTextBox.Text),
SecondsBetweenPings = float.Parse(secondsBetweenPingsTextBox.Text),
MaxResponseTime = int.Parse(maxResponseTimeTextBox.Text),
ServerToPing = serverToPingTextBox.Text,
PerfectThreshold = int.Parse(perfectThresholdTextBox.Text),
GoodThreshold = int.Parse(goodThresholdTextBox.Text),
MediumThreshold = int.Parse(mediumThresholdTextBox.Text)
};
// Save the updated settings to the registry
PingTester.Program.SaveSettings(settings);
PingTester.Program.settingsChanged = true;
// Close the Settings form
Close();
}
private void CancelButton_Click(object sender, EventArgs e)
{
// Close the Settings form without saving
Close();
}
private void configurationLabel_Click(object sender, EventArgs e)
{
}
private void secondsBetweenPingsLabel_Click(object sender, EventArgs e)
{
}
private void pingCountLabel_Click(object sender, EventArgs e)
{
}
private void serverToPingTextBox_TextChanged(object sender, EventArgs e)
{
}
private void maxResponseTimeTextBox_TextChanged(object sender, EventArgs e)
{
}
private void pingCountTextBox_TextChanged(object sender, EventArgs e)
{
}
private void settingsPanel_Paint(object sender, PaintEventArgs e)
{
}
private void additionalPanel_Paint(object sender, PaintEventArgs e)
{
}
}
public class ControlWriter : TextWriter
{
private RichTextBox textbox;
public ControlWriter(RichTextBox textbox)
{
this.textbox = textbox;
}
public override void Write(char value)
{
textbox.Invoke(new MethodInvoker(() =>
{
textbox.AppendText(value.ToString());
ScrollToBottom(textbox);
}));
}
public override void WriteLine(string value)
{
if (!textbox.IsDisposed && textbox.IsHandleCreated)
{
textbox.Invoke(new MethodInvoker(() =>
{
textbox.AppendText(value + "\n");
ScrollToBottom(textbox);
}));
}
}
private void ScrollToBottom(RichTextBox textbox)
{
// Desplazar automáticamente hacia abajo
textbox.SelectionStart = textbox.Text.Length;
textbox.ScrollToCaret();
}
public override Encoding Encoding
{
get { return Encoding.ASCII; }
}
}
}