View difference between Paste ID: 6UAnk13U and UgFJS2Ns
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10
using System.Threading;
11
using System.Net.NetworkInformation;
12
using System.Runtime.InteropServices;
13
14
namespace League_of_Legends_Preping_checker
15
{
16
    public partial class Form1 : Form
17
    {
18
        public Form1()
19
        {
20
            InitializeComponent();
21
            comboBox1.Text = "EUROPE WEST";
22
            if (Properties.Settings.Default.save)
23
            {
24
                comboBox1.Text = Properties.Settings.Default.server;
25
                host = Properties.Settings.Default.IP;
26
            }
27
            backgroundWorker1.RunWorkerAsync();
28
            
29
            
30
        }
31
32
        public const int WM_NCLBUTTONDOWN = 0xA1;
33
        public const int HT_CAPTION = 0x2;
34
35
        [DllImportAttribute("user32.dll")]
36
        public static extern int SendMessage(IntPtr hWnd,
37
                         int Msg, int wParam, int lParam);
38
        [DllImportAttribute("user32.dll")]
39
        public static extern bool ReleaseCapture();
40
41
        string host = "95.172.65.1";
42
43
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
44
        {
45
            while (true)
46
            {
47
                BackgroundWorker backgroundWorker = (BackgroundWorker)sender;
48
                long totalTime = 0;
49
                int timeout = 120;
50
                Ping pingSender = new Ping();
51
                PingReply reply = pingSender.Send(host, timeout);
52
                if (reply.Status == IPStatus.Success)
53
                {
54
                    totalTime = reply.RoundtripTime;
55
                }
56
                backgroundWorker.ReportProgress((int)totalTime);
57
                Thread.Sleep(1000);
58
            }
59
        }
60
61
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
62
        {
63
            if (e.ProgressPercentage != 0)
64
            {
65
                UpdatePing(e.ProgressPercentage);
66
            }
67
        }
68
69
        private void button1_Click(object sender, EventArgs e)
70
        {
71
            backgroundWorker1.RunWorkerAsync();
72
        }
73
74
        Color GetColor(Int32 rangeStart /*Complete Red*/, Int32 rangeEnd /*Complete Green*/, Int32 actualValue)
75
        {
76
            if (actualValue >= rangeEnd) return Color.Red;
77
78
            Int32 max = rangeEnd - rangeStart; // make the scale start from 0
79
            Int32 value = actualValue - rangeStart; // adjust the value accordingly
80
81
            Int32 red = (255 * value) / max; // calculate green (the closer the value is to max, the greener it gets)
82
            Int32 green = 255 - red; // set red as inverse of green
83
84
            return Color.FromArgb((Byte)red, (Byte)green, (Byte)0);
85
        }
86
87
        private void UpdatePing(int ping)
88
        {
89
            try
90
            {
91
                Font font = new Font("Helvetica", 7.0f);
92
                Brush b = new SolidBrush(GetColor(10, 200, ping));
93
                Point p = new Point(0, 3);
94
95
                using (var image = new Bitmap(16, 16))
96
                using (var g = Graphics.FromImage(image))
97
                {
98
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
99
                    g.DrawString(ping.ToString(), font, b, p);
100
                    this.Icon = Icon.FromHandle(image.GetHicon());
101
                    notifyIcon1.Icon = Icon.FromHandle(image.GetHicon());
102
                    label1.Text = ping.ToString() + "ms";
103
                    label1.ForeColor = GetColor(10, 200, ping);
104
                }
105
            }
106
            catch
107
            { }
108
109
        }
110
111
112
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
113
        {
114
            this.Show();
115
        }
116
117
        private void button1_Click_1(object sender, EventArgs e)
118
        {
119
            this.Hide();
120
            notifyIcon1.ShowBalloonTip(3);
121
        }
122
123
        private void button1_MouseHover(object sender, EventArgs e)
124
        {
125
            button1.BackgroundImage = Properties.Resources.btnH2;
126
        }
127
128
        private void button1_MouseLeave(object sender, EventArgs e)
129
        {
130
            button1.BackgroundImage = Properties.Resources.btn3;
131
        }
132
133
        private void panel1_Paint(object sender, PaintEventArgs e)
134
        {
135
        }
136
137
        private void panel1_MouseDown(object sender, MouseEventArgs e)
138
        {
139
            if (e.Button == MouseButtons.Left)
140
            {
141
                ReleaseCapture();
142
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
143
            }
144
        }
145
146
        private void button2_Click(object sender, EventArgs e)
147
        {
148
            if (Properties.Settings.Default.save)
149
            {
150
                Properties.Settings.Default.IP = host;
151
                Properties.Settings.Default.server = comboBox1.Text;
152
                Properties.Settings.Default.Save();
153
            }
154
            else
155
            {
156
                Properties.Settings.Default.save = false;
157
                Properties.Settings.Default.Save();
158
            }
159
            this.Close();
160
        }
161
162
        private void button3_Click(object sender, EventArgs e)
163
        {
164
            this.Hide();
165
            notifyIcon1.ShowBalloonTip(3);
166
        }
167
168
        private void comboBox1_Click(object sender, EventArgs e)
169
        {
170
171
            if (comboBox1.Text == "NORTH AMERICA")
172
            {
173
                comboBox1.Text = "EUROPE WEST";
174
                host = "95.172.65.1";
175
            }
176
            else if (comboBox1.Text == "EUROPE WEST")
177
            {
178
                comboBox1.Text = "EUROPE NORDIC-EAST";
179
                host = "95.172.65.1";
180
            }
181
            else if (comboBox1.Text == "EUROPE NORDIC-EAST")
182
            {
183
                comboBox1.Text = "NORTH AMERICA";
184
                host = "64.7.194.1";
185
            }
186
            else if (comboBox1.Text == "OCEANIA")
187
            {
188
                host = "UNAVAILABLE";
189
            }
190
            else if (comboBox1.Text == "PBE Game Servers")
191
            {
192
                host = "UNAVAILABLE";
193
            }
194
        }
195
196
        private void Form1_Load(object sender, EventArgs e)
197
        {
198
            
199
        }
200
201
        private void button4_Click(object sender, EventArgs e)
202
        {
203
            Form2 settingsForm = new Form2(Cursor.Position.X, Cursor.Position.Y);
204
            settingsForm.ShowDialog(this);
205
        }
206
207
        private void label3_MouseDown(object sender, MouseEventArgs e)
208
        {
209
            if (e.Button == MouseButtons.Left)
210
            {
211
                ReleaseCapture();
212
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
213
            }
214
        }
215
216
        private void comboBox1_MouseHover(object sender, EventArgs e)
217
        {
218
            comboBox1.BackgroundImage = Properties.Resources.btnH2;
219
        }
220
221
        private void comboBox1_MouseLeave(object sender, EventArgs e)
222
        {
223
            comboBox1.BackgroundImage = Properties.Resources.btn3;
224
        }
225
    }
226
}
227
228
229
230
231
232
233
234
235
236
237
238
239
---------------------SETTINGS VINDU----------------------------------------------------------------
240
using System;
241
using System.Collections.Generic;
242
using System.ComponentModel;
243
using System.Data;
244
using System.Drawing;
245
using System.Linq;
246
using System.Text;
247
using System.Threading.Tasks;
248
using System.Windows.Forms;
249
using System.Runtime.InteropServices;
250
using System.Diagnostics;
251
252
namespace League_of_Legends_Preping_checker
253
{
254
    public partial class Form2 : Form
255
    {
256
        private int desiredStartLocationX;
257
        private int desiredStartLocationY;
258
259
        public Form2(int x, int y)
260
        {
261
            InitializeComponent();
262
            this.desiredStartLocationX = x;
263
            this.desiredStartLocationY = y;
264
265
            Load += new EventHandler(Form2_Load);
266
        }
267
268
        public const int WM_NCLBUTTONDOWN = 0xA1;
269
        public const int HT_CAPTION = 0x2;
270
271
        [DllImportAttribute("user32.dll")]
272
        public static extern int SendMessage(IntPtr hWnd,
273
                         int Msg, int wParam, int lParam);
274
        [DllImportAttribute("user32.dll")]
275
        public static extern bool ReleaseCapture();
276
277
        private void button1_Click(object sender, EventArgs e)
278
        {
279
            this.Close();
280
        }
281
282
        private void panel1_MouseDown(object sender, MouseEventArgs e)
283
        {
284
            if (e.Button == MouseButtons.Left)
285
            {
286
                ReleaseCapture();
287
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
288
            }
289
        }
290
291
        private void Form2_Load(object sender, EventArgs e)
292
        {
293
            if (Properties.Settings.Default.save)
294
            {
295
                checkBox1.Checked = true;
296
            }
297
            else
298
            {
299
                checkBox1.Checked = false;
300
            }
301
            this.SetDesktopLocation(desiredStartLocationX, desiredStartLocationY);
302
        }
303
304
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
305
        {
306
            Properties.Settings.Default.save = checkBox1.Checked;
307
        }
308
309
        private void pictureBox1_Click(object sender, EventArgs e)
310
        {
311
            Process.Start("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=sondre%2enjaastad%40gmail%2ecom&lc=NO&item_name=Njastad%2ecom&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted");
312
        }
313
314
        private void label1_MouseDown(object sender, MouseEventArgs e)
315
        {
316
            if (e.Button == MouseButtons.Left)
317
            {
318
                ReleaseCapture();
319
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
320
            }
321
        }
322
    }
323
}