471,084 Members | 1,062 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,084 software developers and data experts.

Can a Windows Form return a value?

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.
Nov 16 '05 #1
3 17198
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

"VMI" wrote:
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.

Nov 16 '05 #2
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" <vo******@yahoo.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 16 '05 #3
VMI wrote:
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
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tim Haughton | last post: by
reply views Thread by Neelima Godugu | last post: by
4 posts views Thread by BrianDH | last post: by
1 post views Thread by RedJoy | last post: by
4 posts views Thread by tshad | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.