-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
116 lines (96 loc) · 3.74 KB
/
Form1.cs
File metadata and controls
116 lines (96 loc) · 3.74 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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 Triangle
{
public partial class form : Form
{
//Constructor
public form()
{
InitializeComponent();
}
//Functions
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
PointF point1 = new PointF((this.Size.Width / 2), (this.Size.Height / 2) - 150.0f);
PointF point2 = new PointF((this.Size.Width / 2) + 150.0f, (this.Size.Height / 2) + 150.0f);
PointF point3 = new PointF((this.Size.Width / 2) - 150.0f, (this.Size.Height / 2) + 150.0f);
using (Pen outlinePen = new Pen(Color.Black, 5))
{
g.DrawLine(outlinePen, point1, point2);
g.DrawLine(outlinePen, point2, point3);
g.DrawLine(outlinePen, point3, point1);
}
}
private void Generate(object sender, EventArgs e)
{
if (a.Value == 0 || b.Value == 0 || c.Value == 0)
{
MessageBox.Show("The sides cannot be negative.", "Generate ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (a.Value + b.Value < c.Value || a.Value + c.Value < b.Value || b.Value + c.Value < a.Value)
{
MessageBox.Show("Sum of two sides is lower than the thirt side!", "Generate ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
La.Text = a.Value.ToString();
Lb.Text = b.Value.ToString();
Lc.Text = c.Value.ToString();
int perimetrN = 0;
float areaN = 0.00f;
perimetrN = (int)(a.Value + b.Value + c.Value);
perimetr.Text = $"P = {perimetrN}";
areaN = (float)(a.Value + b.Value + c.Value) / 2.00f;
areaN = (float)Math.Sqrt(areaN * (areaN - (float)a.Value) * (areaN - (float)b.Value) * (areaN - (float)c.Value));
area.Text = $"A = {areaN:F2}";
if(c.Value == b.Value && b.Value == a.Value && c.Value == a.Value)
{
type.Text = "Equilateral ";
MessageBox.Show("The triangle is equilateral.");
return;
}
float aVal = (float)a.Value;
float bVal = (float)b.Value;
float cVal = (float)c.Value;
bool isRight =
Math.Abs(aVal * aVal + bVal * bVal - cVal * cVal) < 0.001f ||
Math.Abs(aVal * aVal + cVal * cVal - bVal * bVal) < 0.001f ||
Math.Abs(bVal * bVal + cVal * cVal - aVal * aVal) < 0.001f;
string right = isRight ? " and right" : "";
if (a.Value == b.Value || c.Value == b.Value || a.Value == c.Value)
{
type.Text = "Isosceles";
MessageBox.Show($"The triangle is isosceles{right}.");
return;
}
type.Text = $"Scalene{right}";
}
//Operations
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
a.Value = 0;
b.Value = 0;
c.Value = 0;
La.Text = a.Value.ToString();
Lb.Text = b.Value.ToString();
Lc.Text = c.Value.ToString();
perimetr.Text = "P = 0";
area.Text = "A = 0";
type.Text = "Type";
}
}
}