Poner eventos en otros eventos en C# [cerrado]
Frecuentes
Visto 71 equipos
-3
I recently asked a question, but I wasn't clear enough. So I'll try to explain better with some code.
So, I'm making a blank map with two modes, you can change between the modes with two radio-buttons.
I want to put this:
private void hamburgButton_Click(object sender, EventArgs e)
{
city = "Hamburg";
textBoxStadt.Show();
okButton.Show();
}
Dentro de esto:
private void gyakRadioButton_CheckedChanged(object sender, EventArgs e)
{
}
But when I do I get errors stating that a curly bracket is missing.
¿Qué tengo que hacer?
Edit: Here's the entire code:
namespace Német_vaktérkép_1._2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void gyakRadioButton_CheckedChanged(object sender, EventArgs e)
{
private void hamburgButton_Click(object sender, EventArgs e)
{
city = "Hamburg";
textBoxStadt.Show();
okButton.Show();
}
}
}
}
Edit2: OK so what I want to do is that there are two different modes in the blank map. A "learning" mode and a "asking" mode, which tests you. When you choose the learning radio button , the click a button, it shows you it's name, but if you choose the asking radio button, a textbox comes up and you have to type in the city's name, and it checks if you are correct. I currently have two different programs to do thus, and I'm trying to combine them.
1 Respuestas
1
You should explain what you're actually trying to achieve, rather than how you're trying to achieve it. The way you're trying to achieve it (whatever "it" is) makes no sense because you can't put one method inside another. That's right, those are methods, not events. They are event handlers, i.e. methods that are executed when an event is raised.
I assume that what you actually want to do is "click" a Button
cuando un RadioButton
is checked. In that case you have two options:
- Take the code out of the
Button
'sClick
event handler and put it in its own method, then call that method from both event handlers. - Llama a el
Button
'sPerformClick
method in the other event handler to raise theClick
event and thus execute theClick
controlador de eventos.
contestado el 28 de mayo de 14 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# events or haz tu propia pregunta.
locate your unclosed curly bracket. None of what you've shown helps solve the problem - Jonesopolis
You should get some tutorials on events and C# syntax. You can't put one eventhandler into another... - Kamil T
You don't (can't) put event-code inside other event handling code. If you want to link up the logic behind this then you need to ask another, better documented, question. - H H
Hint: you want the same behaviour for 2 handlers.Maybe you can define it elsewhere and have the handlers call it. - MikeSW