-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorEvents.cs
More file actions
123 lines (108 loc) · 4.23 KB
/
Copy pathCalculatorEvents.cs
File metadata and controls
123 lines (108 loc) · 4.23 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
117
118
119
120
121
122
123
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using CalculatorInterface;
using CalculatorOperations;
namespace CalculatorEvents
{
public class CEvents
{
public static void enter_Click(object sender, EventArgs e)
{
string expr = COperations.preformat(CWindow.input.Text);
expr = COperations.preCalculate(expr);
//expr = COperations.preformat(expr);
Console.WriteLine(expr);
Queue<string> equation = COperations.infix_to_postfix(expr);
/*
for (; equation.Count > 0; )
{
Console.Write(equation.Dequeue());
}
Console.WriteLine();
*/
double result = COperations.calculate(equation);
if (CWindow.output.Text.Length != 0)
{ CWindow.output.AppendText(Environment.NewLine); }
CWindow.output.AppendText(CWindow.input.Text + Environment.NewLine);
CWindow.output.AppendText(result + "");
CWindow.input.Clear();
CWindow.input.Focus();
CWindow.output.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
}
public static void degreeMenu_Click(object sender, EventArgs e)
{
System.Windows.Forms.MenuItem mi = sender as System.Windows.Forms.MenuItem;
mi.Checked = true;
if(sender is System.Windows.Forms.MenuItem)
{
System.Windows.Forms.MenuItem g = (System.Windows.Forms.MenuItem)sender;
}
}
public static void button_Click(object sender, EventArgs e)
{
int caretPos = CWindow.input.SelectionStart;
CWindow.input.Text =
CWindow.input.Text.Substring(0, caretPos)
+ sender.ToString()[sender.ToString().Length - 1]
+ CWindow.input.Text.Substring(caretPos + CWindow.input.SelectionLength);
CWindow.input.Select(caretPos+1, 0);
CWindow.input.Focus();
}
public static void clear_Click(object sender, EventArgs e)
{
CWindow.input.Clear();
CWindow.input.Focus();
}
public static void delete_Click(object sender, EventArgs e)
{
int loc = CWindow.input.SelectionStart;
CWindow.input.Text = CWindow.input.Text.Remove(loc,CWindow.input.SelectionLength);
CWindow.input.SelectionStart = loc;
CWindow.input.SelectionLength = 0;
CWindow.input.Focus();
}
//possible error when text is highlighted from left to right
//deletes(backspaces) at the start of the selection rather than where the caret is
public static void backspace_Click(object sender, EventArgs e)
{
int loc = CWindow.input.SelectionStart - 1;
if (loc >= 0)
{
CWindow.input.Text = CWindow.input.Text.Remove(loc, 1);
CWindow.input.SelectionStart = loc;
}
CWindow.input.SelectionLength = 0;
CWindow.input.Focus();
}
//error when text is selected(highlighted) -FIXED
public static void left_Click(object sender, EventArgs e)
{
int loc = CWindow.input.SelectionStart - 1;
if (loc != -1)
CWindow.input.SelectionStart = loc;
CWindow.input.SelectionLength = 0;
CWindow.input.Focus();
}
public static void leftEnd_Click(object sender, EventArgs e)
{
CWindow.input.SelectionStart = 0;
CWindow.input.SelectionLength = 0;
CWindow.input.Focus();
}
public static void right_Click(object sender, EventArgs e)
{
int loc = CWindow.input.SelectionStart + CWindow.input.SelectionLength + 1;
CWindow.input.SelectionStart = loc;
CWindow.input.SelectionLength = 0;
CWindow.input.Focus();
}
public static void rightEnd_Click(object sender, EventArgs e)
{
CWindow.input.SelectionStart = CWindow.input.Text.Length;
CWindow.input.SelectionLength = 0;
CWindow.input.Focus();
}
}
}