Reputation: 21477
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!
Upvotes: 1
Views: 1739
Reputation: 31416
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.
Upvotes: 4
Reputation: 45127
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.
}
Upvotes: 2
Reputation: 564821
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.
Upvotes: 3