CLR: .Net / Mono / Boo / Otros CLR > C#
creacion de dll
picyo:
Hola! He seguido haciendo un poquito ese ejemplo, y bueno, os comento. El programa lo que me hace es que el usuario ingrese una persona ( en menú nuevo) y a esa persona le asignamos el nombre, apellido y la edad ( correspondientes a la clase persona guardada en la dll). Bien, aun no lo he hecho, pero quiero guardar "x"número de personas en un array de strings. Mi problema es que cuando el usuario acaba de meter los datos de una persona, y al presionar el botón de Ok:
- El texto escrito en pantalla desaparece ( eso sale correcto)
- El usuario se dispone a entrar una nueva persona.
Pues bien, aqui es donde no sucede nada ( no se crea una nueva persona) a pesar que existe un delegado para crearla, y creo que está relacionado por el primer punto, el cómo hago desaparecer el texto, y los controles de la pantalla
Bueno, pongo directamente el código:
form1.cs
--- Código: ---using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibreriaPersonas;
namespace UsoDeLibreriaPersonas
{
public partial class Form1 : Form
{
int indice=0;
int i=0;
int j=0;
int[,] IndiceMatriz ;
string[,] GuardaPersonas;
public Form1()
{
InitializeComponent();
VentanaDatosPersona.KeyDown += new System.Windows.Forms.KeyEventHandler(VentanaDatosEscritos);
GuardaPersonas = new string[5, 3]; // personas y sus 3 campos
IndiceMatriz = new int[i, j];
}
private void VentanaDatosEscritos(object sender, KeyEventArgs e)
{
bool nom = false;
bool apell = false;
bool ed = false;
if (e.KeyValue == Convert.ToChar('\r')) {
switch (this.comboBoxDinamico.Text)
{
case "Nombre":
this.comboBoxDinamico.Items.Remove("Nombre");
break;
case "Apellido":
this.comboBoxDinamico.Items.Remove("Apellido");
break;
case "Edad":
this.comboBoxDinamico.Items.Remove("Edad");
break;
}
switch (indice)
{
case 0 :
while (!nom )
{
textBox1.Text += "Nombre:" + VentanaDatosPersona.Text + "\r" + "\n";
textBox1.Visible = true;
GuardaPersonas[i, j] = VentanaDatosPersona.Text;
VentanaDatosPersona.Text = "";
j++;
indice++;
nom = true;
}
break;
case 1:
while(!apell)
{
textBox1.Text += "Apellido:" + VentanaDatosPersona.Text + "\r" + "\n";
GuardaPersonas[i, j] = VentanaDatosPersona.Text;
VentanaDatosPersona.Text="";
indice++;
j++;
apell = true;
}
break;
case 2:
while (!ed)
{
textBox1.Text += "Edad:" + VentanaDatosPersona.Text + "\r" + "\n";
GuardaPersonas[i, j] = VentanaDatosPersona.Text;
VentanaDatosPersona.Text = "";
indice++;
j = 0;
ed = true;
}
MessageBox.Show(GuardaPersonas[0, 0]);
MessageBox.Show(GuardaPersonas[0, 1]);
MessageBox.Show(GuardaPersonas[0, 2]);
this.botonOK.Visible = true;
break;
}
}
}
private void comboBoxDinamico_SelectedIndexChanged(object sender, EventArgs e)
{
string apellidoAux,direccionAux;
VentanaDatosPersona.Visible = true;
switch (comboBoxDinamico.Text)
{
case "Nombre": //MessageBox.Show("Teclea nombre");
VentanaDatosPersona.Visible = true;
VentanaDatosPersona.Focus();
nombreAux = comboBoxDinamico.Text;
break;
case "Apellido":
VentanaDatosPersona.Visible = true;
VentanaDatosPersona.Focus();
apellidoAux = comboBoxDinamico.Text;
break;
case "Edad":
VentanaDatosPersona.Visible = true;
VentanaDatosPersona.Focus();
direccionAux = comboBoxDinamico.Text;
break;
default: MessageBox.Show("por defecto");
break;
}
}
private void RehacerComponentes()
{
//
// comboBoxDinamico
//
this.comboBoxDinamico.FormattingEnabled = true;
this.comboBoxDinamico.Items.AddRange(new object[] {
"Nombre",
"Apellido",
"Edad"});
this.comboBoxDinamico.Location = new System.Drawing.Point(20, 61);
this.comboBoxDinamico.Name = "comboBoxDinamico";
this.comboBoxDinamico.Size = new System.Drawing.Size(121, 21);
this.comboBoxDinamico.TabIndex = 3;
//
// VentanaDatosPersona
//
this.VentanaDatosPersona.Location = new System.Drawing.Point(154, 61);
this.VentanaDatosPersona.Name = "VentanaDatosPersona";
this.VentanaDatosPersona.Size = new System.Drawing.Size(100, 20);
this.VentanaDatosPersona.TabIndex = 4;
this.VentanaDatosPersona.Visible = false;
//
// textBoxVentanaDatosEscritos
//
this.textBoxVentanaDatosEscritos.Location = new System.Drawing.Point(200, 61);
this.textBoxVentanaDatosEscritos.Name = "textBoxVentanaDatosEscritos";
this.textBoxVentanaDatosEscritos.Size = new System.Drawing.Size(100, 20);
this.textBoxVentanaDatosEscritos.TabIndex = 4;
this.textBoxVentanaDatosEscritos.Visible = false;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(52, 169);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(172, 63);
this.textBox1.TabIndex = 5;
this.textBox1.Visible = false;
//
// botonOK
//
this.botonOK.Location = new System.Drawing.Point(522, 95);
this.botonOK.Name = "botonOK";
this.botonOK.Size = new System.Drawing.Size(75, 23);
this.botonOK.TabIndex = 6;
this.botonOK.Text = "OK";
this.botonOK.UseVisualStyleBackColor = true;
this.botonOK.Visible = false;
this.botonOK.Click += new System.EventHandler(this.botonOK_Click);
}
private void NuevaPersona_Click(object sender, EventArgs e)
{
persona1= new Persona();
ComboBox comboBoxDinamico = new ComboBox();
this.Controls.Add(this.comboBoxDinamico);
this.comboBoxDinamico.SelectedIndexChanged += new System.EventHandler(this.comboBoxDinamico_SelectedIndexChanged);
}
private void botonOK_Click(object sender, EventArgs e)
{
VentanaDatosPersona.Clear();
VentanaDatosPersona.Visible = false;
comboBoxDinamico.Hide();
comboBoxDinamico.Visible = false;
textBox1.Clear();
this.textBox1.Visible = false;
RehacerComponentes();
botonOK.Visible = false;
}
}
}
--- Fin del código ---
form1.designer.cs
--- Código: ---namespace UsoDeLibreriaPersonas
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItemNuevo = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemNuevaPersona = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemNuevoAlumno = new System.Windows.Forms.ToolStripMenuItem();
this.comboBoxDinamico = new System.Windows.Forms.ComboBox();
this.VentanaDatosPersona = new System.Windows.Forms.TextBox();
this.textBoxVentanaDatosEscritos = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.botonOK = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemNuevo});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(762, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// toolStripMenuItemNuevo
//
this.toolStripMenuItemNuevo.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemNuevaPersona,
this.toolStripMenuItemNuevoAlumno});
this.toolStripMenuItemNuevo.Name = "toolStripMenuItemNuevo";
this.toolStripMenuItemNuevo.Size = new System.Drawing.Size(54, 20);
this.toolStripMenuItemNuevo.Text = "Nuevo";
//
// toolStripMenuItemNuevaPersona
//
this.toolStripMenuItemNuevaPersona.Name = "toolStripMenuItemNuevaPersona";
this.toolStripMenuItemNuevaPersona.Size = new System.Drawing.Size(155, 22);
this.toolStripMenuItemNuevaPersona.Text = "Nueva Persona";
this.toolStripMenuItemNuevaPersona.Click += new System.EventHandler(this.NuevaPersona_Click);
//
// toolStripMenuItemNuevoAlumno
//
this.toolStripMenuItemNuevoAlumno.Name = "toolStripMenuItemNuevoAlumno";
this.toolStripMenuItemNuevoAlumno.Size = new System.Drawing.Size(155, 22);
this.toolStripMenuItemNuevoAlumno.Text = "Nuevo Alumno";
//
// comboBoxDinamico
//
this.comboBoxDinamico.FormattingEnabled = true;
this.comboBoxDinamico.Items.AddRange(new object[] {
"Nombre",
"Apellido",
"Edad"});
this.comboBoxDinamico.Location = new System.Drawing.Point(20, 61);
this.comboBoxDinamico.Name = "comboBoxDinamico";
this.comboBoxDinamico.Size = new System.Drawing.Size(121, 21);
this.comboBoxDinamico.TabIndex = 3;
//
// VentanaDatosPersona
//
this.VentanaDatosPersona.Location = new System.Drawing.Point(154, 61);
this.VentanaDatosPersona.Name = "VentanaDatosPersona";
this.VentanaDatosPersona.Size = new System.Drawing.Size(100, 20);
this.VentanaDatosPersona.TabIndex = 4;
this.VentanaDatosPersona.Visible = false;
//
// textBoxVentanaDatosEscritos
//
this.textBoxVentanaDatosEscritos.Location = new System.Drawing.Point(200, 61);
this.textBoxVentanaDatosEscritos.Name = "textBoxVentanaDatosEscritos";
this.textBoxVentanaDatosEscritos.Size = new System.Drawing.Size(100, 20);
this.textBoxVentanaDatosEscritos.TabIndex = 4;
this.textBoxVentanaDatosEscritos.Visible = false;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(52, 169);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(172, 63);
this.textBox1.TabIndex = 5;
this.textBox1.Visible = false;
//
// botonOK
//
this.botonOK.Location = new System.Drawing.Point(522, 95);
this.botonOK.Name = "botonOK";
this.botonOK.Size = new System.Drawing.Size(75, 23);
this.botonOK.TabIndex = 6;
this.botonOK.Text = "OK";
this.botonOK.UseVisualStyleBackColor = true;
this.botonOK.Visible = false;
this.botonOK.Click += new System.EventHandler(this.botonOK_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(762, 319);
this.Controls.Add(this.botonOK);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.VentanaDatosPersona);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Uso de dll para nombres";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemNuevo;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemNuevaPersona;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemNuevoAlumno;
private LibreriaPersonas.Persona persona1;
private LibreriaPersonas.Alumno alumno1;
private System.Windows.Forms.ComboBox comboBoxDinamico;
private System.Windows.Forms.TextBox VentanaDatosPersona;
private System.Windows.Forms.TextBox textBoxVentanaDatosEscritos;
string nombreAux;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button botonOK;
}
}
--- Fin del código ---
se que no he utilizado aun la clase persona ( quiero despues usar un array de personas) donde guardar todos estos datos.Mi idea es de momento, que al crear la nueva persona, se sobreescriban los datos ( ya arreglare eso)
picyo:
Bueno, lo que me ocurre es que al clickar en " Nueva Persona", sólo la primera vez que lo hago carga todos los componentes. Hice una funcuión que era cargar componentes, pero no me hace caso. ¿ Por que ?
Navegación
[*] Página Anterior
Ir a la versión completa