I have just tried everything and nothing will work. Have created a new class and set all my coding in there and trying to call the public method from my form1.cs but in my class1 my textbox1 and sender are in red writing.
Code for Form1.cs
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string text;
double operand_1, operand_2, solution;
char Operator;
#region Form Code
private void Form1_Load(object sender, EventArgs e)
{
operand_1 = operand_2 = solution = 0;
text = "0";
Operator = '=';
}
#endregion
#region Number Buttons
private void numbers_Click(object sender, EventArgs e)
{
Class1 cls = new Class1();
cls.Numbers(textBox1.Text);
}
#endregion
#region Operator Buttons
private void operators_Click(object sender, EventArgs e)
{
Class1 cls1 = new Class1();
cls1.Operations();
}
#endregion
}
Then here is my coding for my coding for my Class1:
public class Class1
{
string text;
double operand_1, operand_2, solution;
char Operator;
public void Numbers(string text)
{
Button button = (Button)sender;
text += button.Text;
while (text != "0" && text[0] == '0' && text[1] != '.')
text = text.Substring(1);
textBox1.Text = text;
return text;
}
public void Operations()
{
if (Operator != '=')
{
operand_2 = double.Parse(textBox1.Text);
switch (Operator)
{
case '+': solution = operand_1 + operand_2;
break;
case '-': solution = operand_1 - operand_2;
break;
case '*': solution = operand_1 * operand_2;
break;
case '/': solution = operand_1 / operand_2;
break;
}
Operator = '=';
textBox1.Text = solution.ToString();
}
operand_1 = double.Parse(textBox1.Text);
Operator = char.Parse(((Button)sender).Text);
text = "0";
}
}
Sender error: cannot resolve symbol 'sender' Textbox error: cannot resolve symbol 'textBox1' not sure if it should be public string or void
:'(
Any help would do pls!!!