trato de hacer mediante delegados (porque lo que he visto por aqui no me ha resultado) la deteccion de la pulsacion de la tecla enter de este modo , pero me da fallos continuos de compilacion:
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;
namespace Menus_dinámicos
{
// declaracion de delegado.Un delegado es el controlador de un evento
public delegate void EventReturnKeyPress(KeyPressEventArgs key);
public partial class Form1 : Form
{
TextBox textBoxDin = new TextBox();
Label label1 = new Label();
bool teclaReturn = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ElementoMenuPais_Click(object sender, EventArgs e)
{
ToolStripMenuItem elemento = (ToolStripMenuItem)sender;
MessageBox(elemento);
}
private void MessageBox(ToolStripMenuItem elemento)
{
throw new NotImplementedException();
}
private void paisEscribeCajaTextoDin_Click(object sender, EventArgs e)
{
TextBox label1 = (TextBox)sender;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(100, 60);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(5, 5);
this.label1.Text = "añade país";
this.Controls.Add(this.label1);
//
// textBoxDin
//
this.textBoxDin.Location = new System.Drawing.Point(100, 75);
this.textBoxDin.Name = "textBoxDin";
this.textBoxDin.Size = new System.Drawing.Size(100, 20);
this.textBoxDin.TabIndex = 4;
this.Controls.Add(this.textBoxDin);
}
private void PaisAñadir_Click(object sender, EventArgs e)
{
if (menuPais.DropDownItems.Count ==3)
{
PaisEliminar.Visible = true;
paisSeparador1.Visible = true;
}
string titulo;
titulo = (menuPais.DropDownItems.Count - 2)+ " " + textBoxDin.Text ;
ToolStripMenuItem elemento = new ToolStripMenuItem(titulo);
elemento.Click += new EventHandler(ElementoMenuPais_Click);
menuPais.DropDownItems.Add(elemento);
ToolStripMenuItem elemento2 = new ToolStripMenuItem();
elemento2.Click+=new EventHandler(paisEscribeCajaTextoDin_Click);
}
private void Salir_Click(object sender, EventArgs e)
{
Close();
}
private void PaisEliminar_Click(object sender, EventArgs e)
{
int indUltimo = menuPais.DropDownItems.Count - 1;
menuPais.DropDownItems.RemoveAt(indUltimo);
if (menuPais.DropDownItems.Count==3)
{
PaisEliminar.Visible = false;
paisSeparador1.Visible = false;
}
}
}
class EventReturnKeyPressClass
{
public void EventReturnKeyPressFound(KeyPressEventArgs EventReturnKey)
{
if (EventReturnKey.KeyChar == Convert.ToChar(Keys.Return))
{
}
}
}
}
nuncadetecta la tecla..por que ?????