Sign in to follow this  

[.net] returning a value from a form

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to write a program that opens a second form that will help the end-user calculate information needed in the original form. I cant think of a simple way to make this work though? Basically I have a Text box for the user to enter in a value and a button next to it if they need help calculating it. The second form would come up and ask more specific questions to calculate the value. Then once the button on that form is executed then it would assign that value to the text box on the first form. Thanks a lot I hope this was specific enough.

Share this post


Link to post
Share on other sites

//in first form
CalculateForm frm = new CalculateForm();

if (frm.ShowDialog() == DialogResult.OK)
txtValue = frm.Value;



//second form
public partial class CalculateForm : Form
{
private string _value;

public string Value
{
get { return _value; }
}

public CalculateForm()
{
InitializeComponent();
}


private void btnOK_Click(object sender, EventArgs e)
{
_value = txtValue.Text;
this.DialogResult = DialogResult.OK;
}
}

Share this post


Link to post
Share on other sites

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this