1
I cannot execute a form 2 method through the form 1 button
I call the form but the method does not appear
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//executar
Form2.metodo();
}
}
with the two open forms did not work
Form2 f = new Form2();
f.metodo();
Without Form2 code it is difficult. But I can guess two possibilities. 1. in Form2 declare
metodo()
as static. Eg:public static void metodo(){}
. 2. establish the classForm2
. Eg: 'private void button1_Click(Object Sender, Eventargs e) { Form2 f = new Form2(); f.metodo(); <- call the method from the instance. }`– Augusto Vasques
Where the method is declared
metodo
? Ask the question, is it public? Because if not, you won’t be able to access it anyway.– Roberto de Campos