1

I am building a basic Image editor. In my app, if the user wants to resize the image a new form pops up and asks the user to input an new width and height for the image.

public partial class Form1 : Form
{
...
    private void resizeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        resize resizeForm = new resize();
        resizeForm.ShowDialog();
    }
...
}

I am wondering how I can get the values from the resizeForm and use them to alter the image on the parent form (the Form1 instance).

If this question needs clarification please let me know.

Thanks!

1
  • I guess you would like to show the resizeForm as Modal Commented May 8, 2009 at 1:00

3 Answers 3

4

I assume there are a number of ways to do this. I'd probably use public properties on the resizeForm and then get those when the resizeForm.ShowDialog() returns.

if (resizeForm.ShowDialog() == DialogResult.OK) // or whatever
{
   myVal = resizeForm.Val;
   ...
}

or something like that.

Sign up to request clarification or add additional context in comments.

Comments

3

Setup properties in your "resize" class for the values you want to retrieve. For example, if you add a width property:

public int Width { get; set; }

you will be able to get the width from your Form1 class.

1 Comment

After you add the property and then call ShowDialog, your next line will be after you close the dialog, just use resizeForm.Width, and it should be whatever was set.
2

Add properties to your resize form that your main form can interrogate after the resize form is closed, like ...

DialogResult dr = resizeForm.ShowDialog();

if( dr != DialogResult.Cancel )
{
  var newH = resizeForm.Height;
  var newW = resizeForm.Width;

  // do something with new vals.
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.