3
I’m new to c, so forgive me for making a rookie mistake. I need to put two buttons on the same form,one to call a form, and another to perform a function I’m trying like this:
private void button1_Click(object sender, EventArgs e)
{
dados_bd dados_formulario = new dados_bd();
conection_database conexao = new conection_database();
dados_formulario.NOME = textBox1.Text;
dados_formulario.LOCAL_ARMAZENAMENTO = textBox2.Text;
dados_formulario.DESCRICAO = textBox3.Text;
conexao.cadastro(dados_formulario);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
Form2 teste = new Form2();
teste.ShowDialog();
}
If I put the function of calling another form in button1, it works, but when I set it to button 2, it doesn’t. Even, no function is available to button2. I would like some clarification on this.
I changed the code, as suggested above, but it didn’t work. So I put the suggestion in the button1
, that it was the only one that worked, and the function that was previously assigned to it, on the button that did not respond.
But, behold, now the two buttons are calling to form2
, even if the function is assigned only to the button1
:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
new Form2().Show();
}
public void button2_Click(object sender, EventArgs e)
{
dados_bd dados_formulario = new dados_bd();
conection_database conexao = new conection_database();
dados_formulario.NOME = textBox1.Text;
dados_formulario.LOCAL_ARMAZENAMENTO = textBox2.Text;
dados_formulario.DESCRICAO = textBox3.Text;
conexao.cadastro(dados_formulario);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
}
And Voce is sure that the event is assigned to the element?
– Aline
I’m not sure, tell me how, I repeat, I’m new.
– Igor
Double-click the button2 and check if it is going to the button2_Click method or if it is generating a new method.
– Tiago S
When I double click, it falls into the button1 method. Do I just need to make this reference to the Button2_click menu? How do I?
– Igor
managed to solve your problem Igor ? please check the reply. Thank you
– Rovann Linhalis