Tengo un codigo en c# en el cual abre una ventana al darle click al boton la cual es la segunda ventana y se ingresan los datos, una vez ingresado los datos se le da click y se cierra la segunda ventana pero se duplica la primera ventana uno con los datos y otra vacía,alguien sabe por que sucede esto ya intente cerrar la ventana principal los combobox y los texbox tiene acceso publico no se si tenga algo que ver eso que se duplique el mismo formulario
Ventana 1 la cual se duplica dos veces:
public partial class Form1 : Form {
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
}
private void btn_SC_Click(object sender, EventArgs e)
{
FColores fColores = new FColores();
fColores.ShowDialog();
}
}
Ventana 2
public partial class FColores : Form
{
Form1 form = new Form1();
public FColores()
{
InitializeComponent();
}
private string a;
private double b;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox1.SelectedIndex)
{
case 0:
form.button1.BackColor = Color.Black;
break;
case 1:
a = "1";
form.button1.BackColor = Color.Maroon;
break;
case 2:
a = "2";
form.button1.BackColor = Color.Red;
break;
case 3:
a = "3";
form.button1.BackColor = Color.Orange;
break;
case 4:
a = "4";
form.button1.BackColor = Color.Yellow;
break;
case 5:
a = "5";
form.button1.BackColor = Color.Green;
break;
case 6:
a = "6";
form.button1.BackColor = Color.Blue;
break;
case 7:
a = "7";
form.button1.BackColor = Color.Violet;
break;
case 8:
a = "8";
form.button1.BackColor = Color.Gray;
break;
case 9:
a = "9";
form.button1.BackColor = Color.White;
break;
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox2.SelectedIndex)
{
case 0:
a += "0";
form.button2.BackColor = Color.Black;
break;
case 1:
a += "1";
form.button2.BackColor = Color.Maroon;
break;
case 2:
a += "2";
form.button2.BackColor = Color.Red;
break;
case 3:
a += "3";
form.button2.BackColor = Color.Orange;
break;
case 4:
a += "4";
form.button2.BackColor = Color.Yellow;
break;
case 5:
a += "5";
form.button2.BackColor = Color.Green;
break;
case 6:
a += "6";
form.button2.BackColor = Color.Blue;
break;
case 7:
a += "7";
form.button2.BackColor = Color.Violet;
break;
case 8:
a += "8";
form.button2.BackColor = Color.Gray;
break;
case 9:
a += "9";
form.button2.BackColor = Color.White;
break;
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox3.SelectedIndex)
{
case 0:
form.button3.BackColor = Color.Black;
break;
case 1:
form.button3.BackColor = Color.Maroon;
form.txt_Multi.Text = "0";
a += "0";
break;
case 2:
form.button3.BackColor = Color.Red;
form.txt_Multi.Text = "00";
a += "00";
break;
case 3:
form.button3.BackColor= Color.Orange;
form.txt_Multi.Text = "000";
a += "000";
break;
case 4:
form.button3.BackColor = Color.Yellow;
form.txt_Multi.Text = "0000";
a += "0000";
break;
case 5:
form.button3.BackColor = Color.Green;
form.txt_Multi.Text = "00000";
a += "00000";
break;
case 6:
form.button3.BackColor = Color.Blue;
form.txt_Multi.Text = "000000";
a += "000000";
break;
case 7:
form.button3.BackColor = Color.Violet;
form.txt_Multi.Text = "0000000";
a += "0000000";
break;
case 8:
form.button3.BackColor = Color.Gray;
form.txt_Multi.Text = "" + 0.1;
b = double.Parse(a) * 0.1;
a = b.ToString();
break;
case 9:
form.button3.BackColor = Color.White;
form.txt_Multi.Text = "" + 0.01;
b = double.Parse(a) * 0.01;
a = b.ToString();
break;
}
}
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox4.SelectedIndex)
{
case 0:
form.button4.BackColor = Color.Red;
form.txt_Tolerancia.Text = "+-2%";
break;
case 1:
form.button4.BackColor = Color.Gold;
form.txt_Tolerancia.Text = "+-5%";
break;
case 2:
form.button4.BackColor = Color.Silver;
form.txt_Tolerancia.Text = "+-10%";
break;
}
}
private void btn_Calcular_Click(object sender, EventArgs e)
{
form.Show();
this.Close();
}
}