-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx4.cs
More file actions
94 lines (76 loc) · 2.54 KB
/
Copy pathEx4.cs
File metadata and controls
94 lines (76 loc) · 2.54 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
86
87
88
89
90
91
92
93
94
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 HW1
{
public partial class Ex4 : Form
{
Point startPoint=new Point(0,0);
Point endPoint= new Point(40,50);
Rectangle rect = new Rectangle();
System.Drawing.Graphics formGraphics;
bool isDown = false;
public Ex4()
{
InitializeComponent();
label1.Text = "";
}
private void Ex4_MouseMove(object sender, MouseEventArgs e)
{
if (isDown == true)
{
this.Refresh();
Pen drwaPen = new Pen(Color.Navy, 1);
rect = new Rectangle(Math.Min(e.X, startPoint.X),
Math.Min(e.Y, startPoint.Y),
Math.Abs(e.X - startPoint.X),
Math.Abs(e.Y - startPoint.Y));
formGraphics = this.CreateGraphics();
formGraphics.DrawRectangle(drwaPen, rect);
}
}
private void Ex4_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button==MouseButtons.Left)
{
isDown = true;
startPoint.X = e.X;
startPoint.Y = e.Y;
}
}
void SendMessage(string str)
{
MessageBox.Show(str,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
private void Ex4_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDown = false;
if (Math.Abs(e.X-startPoint.X)>=10 )
{
endPoint.X = e.X;
endPoint.Y = e.Y;
}
else
{
SendMessage("The minimum values of should be 10x10");
this.Refresh();
}
}
}
private void Ex4_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button==MouseButtons.Right&&startPoint.X<e.X&&e.X<endPoint.X&& startPoint.Y < e.Y && e.Y < endPoint.Y)
{
label1.Text = $"Start Coordinates: {rect.Location}\n Area: {rect.Width * rect.Height}";
}
}
}
}