HighTechTalks DotNet Forums  

Modal dialogs

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss Modal dialogs in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Reg Rat
 
Posts: n/a

Default Modal dialogs - 12-14-2005 , 12:21 PM






Hi,

I'm trying to do something that appears extremely simple but I can't find an
obvious solution for it. I want to create a modal dialog which, upon being
displayed, immediately starts doing some work which may take some time (the
dialog is simply to display progress via a progress bar and an updating
label with a cancel button). The obvious solution is to put the call to the
method doing the work in the Load event handler of the dialog, but this
causes the work to start before the dialog has been displayed.

It looks like the only option I have is to kick off a new thread in the Load
handler which will do the work, but this seems a bit over the top for my
purposes, particularly as this thread would need to call into the UI thread
to update the dialog.

Is there an obvious answer I have missed?

Thanks in advance,
Mike



Reply With Quote
  #2  
Old   
Richard Grimes
 
Posts: n/a

Default Re: Modal dialogs - 12-15-2005 , 08:35 AM






Reg Rat wrote:
Quote:
progress bar and an updating label with a cancel button). The obvious
solution is to put the call to the method doing the work in the Load
event handler of the dialog, but this causes the work to start before
the dialog has been displayed.
There are various events you can try: VisibleChanged, HandleCreated,
Activated, I cannot remember the order they are called, but they are
worth a try. Another option is the Paint event is called. If you use
..NET 2.0 you can use the Shown event.

Richard
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm




Reply With Quote
  #3  
Old   
Pascal Duti
 
Posts: n/a

Default Re: Modal dialogs - 01-06-2006 , 06:50 AM



Hi,

I come from a Delphi background so this might or might not work in .NET.

The idea is that in the Activated event of the form, you send a windows
message to the form itself. In the form you define an event handler for
that message and in that eventhandler you do the processing.

How does this resolve your problem ? The message you sent gets only
dispatched to the the form when all previous messages are processed.
Painting the form is also done via messages (WM_PAINT). So once you
receive your message the form is already painted and created (because
all WM_PAINT are processed before your message.

Sounds complicated but is really simple to do. If you know how to send a
message (PostMessage in Win API) and how to define an eventhandler for
messages (Dispatch ?)









Richard Grimes wrote:
Quote:
Reg Rat wrote:

progress bar and an updating label with a cancel button). The obvious
solution is to put the call to the method doing the work in the Load
event handler of the dialog, but this causes the work to start before
the dialog has been displayed.


There are various events you can try: VisibleChanged, HandleCreated,
Activated, I cannot remember the order they are called, but they are
worth a try. Another option is the Paint event is called. If you use
.NET 2.0 you can use the Shown event.

Richard


Reply With Quote
  #4  
Old   
Alan Pretre
 
Posts: n/a

Default Re: Modal dialogs - 01-09-2006 , 11:49 AM



"Reg Rat" <reg (AT) hotmail (DOT) com> wrote

Quote:
It looks like the only option I have is to kick off a new thread in the
Load handler which will do the work, but this seems a bit over the top for
my purposes, particularly as this thread would need to call into the UI
thread to update the dialog.
Hi. Use the BackgroundWorker class. You can set this all up in your
FormLoad event. It's the cat's meow.

http://msdn2.microsoft.com/en-us/library/4852et58.aspx

-- Alan




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.