Link multiple window forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I'm building an engineering calculator. The calculator receives input
parameters in main window form, and I would like the results to be presented
on another form (pop-up window form), however, I'm new to C# and I don't know
how to link the i/o data from one form to another. I would be appreciated if
anyone give me some idea on how to do so.

Regards,

Johnny
 
Johnny,

The C# (OOP) way is to, on your results form, have private member variables
that will hold your data. You then expose these to the outside world via
properties that allow a parent object to set or get (or both) values on each
data member.

I imagine it would look something like this...


inputform.cs
------------

// Inside the event handler for the button the user clicks on to get a
result.
// Named "Calculate" or something like that

// code to retrieve all the user parameters goes here

// code to put results into local variables here

// Display results
ResultsForm results = new ResultsForm(); //creates the result form
results.Pressure = appliedPressure;
results.Movement = appliedMovement;
// other engineering type values to pass here
results.ShowDialog(); // display the form

ResultsForm.cs
----------------

// variable declarations here
string pressureApplied = "";
int movementExpected = -1;
// other engineering type variables declared here

// Properites declared here
string Pressure
{
// if the parent needs to set this value externally
set
{
pressureApplied = value;
}

// if the parent needs to get this value
{
return pressureApplied ;
}
}

int Movement
{
set
{
movementExpected = value;
}
}

// all your functions here can now access pressureApplied and
movementExpected.
// if you want to generate a report, this should be done from the
Load event handler,
// and not the constructor since at time of construction the values
haven't been passed
// through yet...

Hope that helps.

Thanks.

Daniel.
 
Back
Top