Can a Windows Form return a value?

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

In my Windows application, the main Form (Form_Main) calls a small Form
(Form_X) that checks a file. Basically, I pass the name of the file through
frmX's constructor and then I display it with ShowDialog(). In the
constructor, I call the method that runs the validation process. Is it
possible that, once this process (which returns a bool) is finished, that it
returns this value to the main Window ? Baically, I want to pass the return
value of checkRecordsLength() to Form_Main without having to add any
variables or references.

So, from Form_Main, I instantiate frmX:

Form_X frmX= new Form_X(sFileName);
frmCheck.ShowDialog();

---------------------------
In my Form_X:

public Form_X(string sFileName, ref bool isValid)
{
InitializeComponent();
_sFileName = sFileName;
checkRecordsLength();
}
private bool checkRecordsLength()
{
/* validate _sFileName *./
if (fileIsValid)
return true;
else
return false;
}



Thanks.
 
You might use a public static variable in a component (dll) and use this
component to transfer information from one form /proccess to another by
setting this variable status before closing the proccess, and retrieving it's
value through the the main form.
Hope it helps
Michael
 
ShowDialog returns a DialogResult which is an enum. Among the values are YES
and NO. You can easily use these to return the equivalent of a bool.

Thomas P. Skinner [MVP]
 
VMI said:
In my Windows application, the main Form (Form_Main) calls a small Form
(Form_X) that checks a file. Basically, I pass the name of the file through
frmX's constructor and then I display it with ShowDialog(). In the
constructor, I call the method that runs the validation process. Is it
possible that, once this process (which returns a bool) is finished, that it
returns this value to the main Window ? Baically, I want to pass the return
value of checkRecordsLength() to Form_Main without having to add any
variables or references.
Ignoring you preference to not add any variables :)

Overload showdialog and return your bool result as an out or ref param
is what I have done in the past.

This works very neatly and has the added advantage of not perverting
dialogresult to your specific case (IMHO :) )

Other ideas always appreciated.

Cheers
JB
 
Back
Top