Вопрос

I have a winform that has several modules that are created dynamically based on information in a database. each of these modules has an edit button. I want to be able to pass in an object through to the click handler and then to the new form yet I cannot figure out how. Any help would be awsome here is what i have:

PingServer temp = manager.servers.ElementAt(i).Value;

EditButton.Click += new EventHandler(openEditor(temp));

private void openEditor(PingServer server)       
{            
    EditConnectionForm editConnection = new EditConnectionForm(server);
    editConnection.ShowDialog();
}
Это было полезно?

Решение

Close over the variable using a lambda:

EditButton.Click += (sender, args) => openEditor(temp);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top