Click here to Skip to main content
15,888,300 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working with windowsFrom in c#. I am trying to call mainfrom method in one of the from in user control.
I have mainfrom like this

C#
namespace Project
   {
     public partial class MainForm : Form
      {
       public MainForm()
       {
           InitializeComponent();
       }

       public void TempCommand()
         {
          StartTemp();
         }
      }
    }

I have the button click in the user control. When i click that button then it will open another form. I have the code like this in the user control.

C#
private TempCalib _tempCalib = new TempCalib();
 
       private void calibBtn_Click(object sender, EventArgs e)
        {
            _tempCalib.Show();
        }

it will open another from and i have one button in that from. I need to call mainfrom method when i click "Ok" button in this from.

C#
namespace Project
  {
  public partial class TempCalib : Form
  {

      public TempCalib()
      {
          InitializeComponent();
      }

      private void OkButton_Click(object sender, EventArgs e)
      {
         // I need to call the mainfrom "TempCommand" method here.
          this.Hide();
      }


     }
   }

Can anyone help me how to do this.

Thanks.
Posted
Updated 16-Jul-13 2:12am
v2

1 solution

I would have the usercontrol raise an event and subscribe to it in the main form. When the event is raised, you call your method.

Griff gives you the general idea here:
Transferring information between two forms, Part 2: Child to Parent[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900