When I try to create an object of the form class within the form class, it gives an exception as stackoverflow occured.However, when I declare the object of form class within a method,it works fine.the code is as follows:
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
**Form1 f1 = new Form1();**//gives stackoverflow exception.......
char[] ar = new char[15];
int flag = 0, end;
double val1, val2, res;
string oprt;
public Form1()
{
InitializeComponent();
}
private void masters(object sender, EventArgs e)
{
ar[i] = char.Parse(((Button)sender).Text);
if (char.IsDigit(ar[i]))
{
if (flag != 0)
{
if (textBox1.Text == oprt)
{
textBox1.Clear();
}
}
else
{
if (end == 1)
{
textBox1.Clear();
end = 0;
}
}
Button ansbox = sender as Button;
textBox1.Text += ansbox.Text;
}
else if (char.IsSymbol(ar[i]))
{
if (textBox1.TextLength != 0)
{
val1 = double.Parse(textBox1.Text);
textBox1.Clear();
Button bt = sender as Button;
if (bt != null)
textBox1.Text = bt.Text;
oprt = bt.Text;
// dot.Enabled = true;
flag = 1;
}
}
}
private void button14_Click(object sender, EventArgs e)
{
if (textBox1.TextLength != 0)
{
val2 = double.Parse(textBox1.Text);
switch (oprt)
{
case "+": res = val1 + val2;
break;
case "-": res = val1 - val2;
break;
case "*": res = val1 * val2;
break;
case "/": res = val1 / val2;
break;
}
textBox1.Text = res.ToString();
flag = 0;
end = 1;
}
}
}
}
}