tags:

views:

306

answers:

3

Hello, 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!

+3  A: 

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.

Reed Copsey
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.
Joshua Belden
+2  A: 

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.
}
JP Alioto
+4  A: 

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.

itsmatt