CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: ShowDialogue

  1. #1
    Join Date
    Sep 2010
    Posts
    9

    ShowDialogue

    Here's the relation among the 3 forms:

    Form A calls Form B which is independent of it (I use Show() here).
    Then Form A calls Form C which is obliged to do some operations before returning back to Form A(I use ShowDialogue() here).
    But here's the problem, form C also takes up the focus of form B, so B is not independent of C. Is there anyway that B could be active when C is open? I want to do some operations on B while C is open.

    Many thanks.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ShowDialogue

    The only way to do it is to open C with Show( ).

    The reason is that there can only be one active modal form per application at a time.

    If you open C with ShowDialog( ) it will be modal and prevent you from accessing B until you close C.

  3. #3
    Join Date
    Sep 2010
    Posts
    9

    Re: ShowDialogue

    ok, so this means that i have to handle the relation between A and C myself. I mean A should 'sleep' till C is closed. But to let B still be accessible while A is waiting for the answer of C, do I have to make B be another thread apart from the main thread?

    thank you

  4. #4
    Join Date
    Sep 2010
    Posts
    9

    Re: ShowDialogue

    Or instead, can I create a new thread to take care of B, then A calls C as a modal form. Then will B be accessible when C is open?

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ShowDialogue

    Don't use threads - you'll want to keep all of the UI in the same thread.

    You can't 'sleep' A either. If you do, you'll block B & C too.

    What you can do is to disable the controls in A before opening C and reenable them when C closes.

  6. #6
    Join Date
    Sep 2010
    Posts
    9

    Re: ShowDialogue

    thank you!! but it's not as easy as disable the controls. A is waiting for the data from C to resume some calculation. if using one thread, I cannot put a while loop to wait, otherwise it will block the whole process. so in the end what i did is to create a thread to run form B and use delegate to invoke some functions from time to time. luckily the operations on B is not very complex.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ShowDialogue

    Quote Originally Posted by vivienlwt View Post
    thank you!! but it's not as easy as disable the controls. A is waiting for the data from C to resume some calculation. if using one thread, I cannot put a while loop to wait, otherwise it will block the whole process. so in the end what i did is to create a thread to run form B and use delegate to invoke some functions from time to time. luckily the operations on B is not very complex.
    You misunderstand about threading. In threading, you put the worker operations in the threads, not the UI. Your mistake is running form B from the worker thread. Keep Form B in the main UI thread and use delegates to update the UI components (in the UI thread).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured