|
-
Mar 20th, 2006, 04:32 PM
#1
Thread Starter
Lively Member
show modal dialog while running code in main form
hi all, i was wondering if there is any way to show a modal dialog box, but run code while the owner form is blocked. Setting the main form.Enabled = false to block it redraws all the controls as grayed and disabled, which i do not need. The following pseudo-code is about what would be nice:
Code:
private void WorkButton_Click(object sender, System.EventArgs e) {
ProcessingForm processing = new ProcessingForm();
processing.ShowDialogAsync(this);
for(int i = 0; i < 1000; i++) {
// do stuff
}
processing.Close();
}
Thanks in advance for any help!
-
Mar 20th, 2006, 06:36 PM
#2
Re: show modal dialog while running code in main form
You should show the dialogue in the UI because it is a UI element. You can start a new thread or use a delegate to make an asynchronous method call to perform your other task before displaying the dialogue. If you show the dialogue in a different thread then it will not behave as a modal dialogue.
-
Mar 21st, 2006, 02:41 PM
#3
Thread Starter
Lively Member
Re: show modal dialog while running code in main form
i have a multi-threaded setup working, but the app is simple, and i'll be blocking the main interface while it is processing, so going to multithreaded seems a bit overkill. what i really need is a way to disable the main form but still draw it as if it's enabled.
Code:
private void WorkButton_Click(object sender, System.EventArgs e) {
ProcessingForm processing = new ProcessingForm();
this.Enabled = false; // except don't gray out controls on this form
processing.Show();
for(int i = 0; i < 1000; i++) {
// do stuff
}
processing.Close();
this.Enabled = true;
}
-
Apr 5th, 2006, 03:29 PM
#4
Thread Starter
Lively Member
Re: show modal dialog while running code in main form
-
Apr 5th, 2006, 05:12 PM
#5
Re: show modal dialog while running code in main form
If you want the main form to be refreshed as needed then multithreading is the way to go. Otherwise the only way to refresh it will be for you to call Refresh or DoEvents at intervals through your code. If you want the mani form disabled then you can popup a modal dialogue from the main form and then start the worker thread from that. It will block access to the main form while the thread is executing and it can show progress or whatever if desired.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|