-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
85 lines (70 loc) · 2.7 KB
/
Form1.cs
File metadata and controls
85 lines (70 loc) · 2.7 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Button_Practice_two
{
public partial class Form1 : Form
{
Random r = new Random();
public Form1()
{
InitializeComponent();
}
public void Mouse_Hover(object obj, EventArgs argv)
{
if (((Button)obj).BackColor == Color.Red)
{
var relativePoint = this.PointToClient(Cursor.Position);
((Button)obj).Location = new Point(relativePoint.X - ((Button)obj).Size.Width / 2, relativePoint.Y - ((Button)obj).Size.Height / 2);
this.Text = Cursor.Position.ToString();
}
}
//public void Mouse_Click(object obj, MouseEventArgs argv)
public void Mouse_Click(object obj, EventArgs argv)
{
MouseEventArgs me = (MouseEventArgs)argv;
//if (me.Button == System.Windows.Forms.MouseButtons.Right)
//{
// Form_Reload();
//}
if (me.Button.Equals(MouseButtons.Left) && ((Button)obj).BackColor == Color.Red)
{
Form_Reload();
}
}
public void Form_Reload()
{
button_1.Dispose();
button_2.Dispose();
this.button_1 = new Button();
this.button_2 = new Button();
this.button_1.Size = new Size(50, 50);
this.button_2.Size = new Size(50, 50);
this.button_1.Location = new Point(r.Next(0, this.Size.Width - this.button_1.Size.Width), r.Next(0, this.Size.Height - this.button_2.Size.Height));
this.button_2.Location = new Point(r.Next(0, this.Size.Width - this.button_2.Size.Width), r.Next(0, this.Size.Height - this.button_2.Size.Height));
//if (r.Next() % 2 == 1)
if (r.Next(0, 2) == 1)
{
this.button_1.BackColor = Color.Red;
this.button_2.BackColor = Color.Green;
}
else
{
this.button_1.BackColor = Color.Green;
this.button_2.BackColor = Color.Red;
}
button_1.MouseMove += new System.Windows.Forms.MouseEventHandler(Mouse_Hover);
button_2.MouseMove += new System.Windows.Forms.MouseEventHandler(Mouse_Hover);
button_1.MouseClick += new MouseEventHandler(Mouse_Click);
button_2.MouseClick += new MouseEventHandler(Mouse_Click);
this.Controls.Add(button_1);
this.Controls.Add(button_2);
}
}
}