Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add something like ShowDialog to a custom User Control?

When a user selects a button a custom user control is added to the form. This user control provides the ability to enter in some values.

How do I wait for the user control to complete before changing the value on my main form?

I was thinking of something like this:

customControl ylc = new customControl();
ylc.Location = new Point(11, 381);
ylc.Parent = this;
ylc.BringToFront();

if(ylc.ShowDialog() == DialogResult.OK)
{
   this.lblSomeText.Text = ylc.PublicPropertyValue
}

UPDATE1

The user control can't be added to its own form. On some forms it is 'embedded-in' and on other forms it is dynamically created as needed.

UPDATE2

This SO link was helpful.

My final solution looks like (I hide the usercontrol when 'completed'):

customControl ylc = new customControl();
ylc.Location = new Point(11, 381);
ylc.Parent = this;
ylc.BringToFront();
ylc.VisibleChanged += new EventHandler(ylc_VisibleChanged);    
ylc.Show();

Then this code goes in the 'Visiblechanged' event:

if(ylc.ShowDialog() == DialogResult.OK)
{
   this.lblSomeText.Text = ylc.PublicPropertyValue
}
like image 524
John M Avatar asked Jul 23 '10 16:07

John M


1 Answers

A user control does not really complete does it? I think what you're trying to do might be better served by putting the user control on its own form and calling ShowDialog on that.

like image 162
msergeant Avatar answered Sep 23 '22 01:09

msergeant