Mr Celetron

Mr Celetron

  • NA
  • 10
  • 3.2k

How to pass value to unspecified object using delegate C#

Jun 30 2012 2:22 AM
I have a FlowLayoutPanel containing an unspecified number of Labels, when I double click in one of them, a new Form containing a TextBox and a Button will appear, here is the code:

    foreach (Label lb in FlowLayoutPanel1.Controls)
    {
        lb.MouseDoubleClick+=new MouseEventHandler(lb_MouseDoubleClick);
    }
    
    private void lb_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        NewForm form = new NewForm();
        form.ShowDialog();
        ((Label)sender).Text = ...;//I want get text from TextBox of the NewForm here
    }

I want get Text from TextBox of the NewForm and assign Text to the object that invoke the NewForm when user click the Button of the NewForm, I know to use properties or static variable to do this, but I dont know how to use delegate to do this? Please help me,Thanks!

Answers (2)