Execute Code after showDialog()

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi

I have a Windows Form (myForm()) doing somethig.
myForm() should be modal.
Normaly the action initated by user - pressing a Button, callling
myForm:DoSomething()

Now i will use the same Form like "batch-processing", starting
:DoSomething() in my code:

It'c clear to me that the following code can not work:

myForm:ShowDialog();
myForm:DoSomething()

--> what is the best way to do this ?

- Is there a "AfterShowEvent" ?, or which event is fired after dotnet
is "to be done doing everything with myDialog()"

- As well I think to use a timer....

Thanks
Peter
 
Hi,


myForm:ShowDialog();
myForm:DoSomething()

--> what is the best way to do this ?

No clear why this cannot work, if you are going to implement it as a batch
it will have no user interaction, so most probably myForm will do something
(without requiring user interaction) and will return ( by calling
Form.Close ) so your code "may" work.

cheers,
 
If you're doing batch processing, why does the form need to be modal
(or shown at all)? Just create it, manipulate the form, and then
dispose it. Or use Show(), manipulate it, then close it.

If that won't work, you can add a VisibleChanged event to the form:

using (MyForm frm = new MyForm()) {
frm.VisibleChanged += new EventHandler(MyFormVisibleChanged);
frm.ShowDialog();
frm.VisibleChanged -= new EventHandler(MyFormVisibleChanged);
}
....
private void MyFormVisibleChanged(object sender, EventArgs e) {
MyForm frm = sender as MyForm;
if (frm != null && frm.Visible) {
// do something with frm
}
}

Jesse
 
Good Joke...

my Code should not run after the dialog is closed. I look for a
possibility to start code "from the outside of myDialog" when myDialog
is active.

myForm:Show();
myForm:DoSomething()

do this, but then myDialog ist not modal.

Peter.
 
Hi,

You have to use a thread then, I'm still not clear of what you want,
If you want that DoSmething() is executed when the dialog is being
displayed you have two potions:
1- call DoSomething in the Form_load of the dialog
2- use a thread


cheers,
 
Back
Top