I have wrote a code with this description:
First button calls FuncPopup(); function, after that every popup dialog creates new button. New button Create FuncPopup();. Old buttons should have various behavior.
private void FuncPopup()
{
FuncMenu popup = new FuncMenu();
popup.ShowDialog();
if (popup.DialogResult.HasValue && popup.DialogResult.Value)
{
i++;
newBtn[i] = new Button();
FuncGird.Children.Add(newBtn[i]);
Grid.SetColumn(newBtn[i], i);
Grid.SetRow(newBtn[i], j);
newBtn[i].Click += (sender, e) => clicked(i);
}
}
void clicked(int g) {
if (g >= i)
{
FuncPopup();
}
else (g < i){
OtherFunction();
}
}
i is a global variable. I expect Old buttons run OtherFunction(); but they always run FuncPopup();.