I'm new to C #, so forgive some rookie error. I need to put two buttons on the same form, one to call one form, and another to execute 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 on button1, it works, but when I set it the same for button 2, it does not. In fact, no function is available to button2. I would like some clarification on this.
I changed the code, as suggested above, but it did not work. So I put the suggestion in the function of button1
, which was the only one that worked, and the function that was previously assigned to it, in the button that did not respond.
But now the two buttons are calling form2
, even the function being assigned only to 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 = "";
}
}
}