문제

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