Este es el form 1
Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
class Persona
{
string nombre;
int edad;
public void setNombre(string n)
{
nombre = n;
}
public void setEdad(int n)
{
edad = n;
}
public string getNombre()
{
return nombre;
}
public int getEdad()
{
return edad;
}
public void grabarDatos()
{
//Aca deberia meter el codigo para el "INSERT" de sql
}
}
namespace Prueba_de_registros
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.Show();
}
}//Form 1
}
Y este es el form 2
Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Prueba_de_registros
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
/*Boton guardar y salir*/
private void button1_Click(object sender, EventArgs e)
{
Persona obj = new Persona();
obj.setNombre(textBox1.Text);
obj.setEdad(Convert.ToInt32(maskedTextBox1.Text));
obj.grabarDatos();
Close(); //Cierra el formulario
}
/*Boton guardar y continuar*/
private void button3_Click(object sender, EventArgs e)
{
Persona obj = new Persona();
obj.setNombre(textBox1.Text);
obj.setEdad(Convert.ToInt32(maskedTextBox1.Text));
obj.grabarDatos();
textBox1.Clear();
maskedTextBox1.Clear();
}
/*Boton salir*/
private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}