Button i groupbox

0

Witam, tworząc dynamicznie button w groupBoxie da radę sprawdzić potem w któym groupboxie jest dany button?

GroupBox n = new GroupBox();
 i += 1;
 n.Text = "nr:" + i.ToString();
 n.Location = new Point(X, Y);
n.Size = new Size(350, 22);
 tabPage4.Controls.Add(n);

Button b = new Button();
b.Text = "TEST";
b.Location = new Point(712, 19);
b.Size = new Size(32, 23);
n.Controls.Add(b);
b.Click += new EventHandler(bCLICK);

void bCLICK(object sender, EventArgs e)
        {
            //MessageBox.Show("klikles w button, ktory jest w groupboxie...");
        }


2
void bCLICK(object sender, EventArgs e)
{
   var btn = sender as Button;
   var gb = btn.Parent as GroupBox;
   MessageBox.Show("klikles w button, ktory jest w groupboxie "+ gb.Name);
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1