CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Posts
    25

    Keep a Modal Form WIthin a Parent Form

    Can anyone help me ? This is one of the problems with VB i have never found a solution for and that is to keeps coming up as a issue.

    For Astecic reasons my boss wants to keep all forms opened from the main application window to stay within the that forms boundries. ie it cant be dragged outside Main forms Borders

    Their are 2 ways i have been able to do this as the MDI form and Child Forms of VB or by Using the SetParent Function of the Windows API.

    The Problem that im encountering is the following I am required for my Parent Form to wait until the other form is done processing before its code continues.

    I know the easiest way to do this is make a form vbModal when i Show it but this will not work on MDI forms or forms where i have used the setparent api funtion. And I know the other option is to create a message loop for each child form and wait for my child form to send back a message but I find this cumbersome and hard to follow when trying to read the code after as you have to jump back and forth from form to form when trying to follow the code later.

    Any Ideas Would BE Much Appreciated

    Jerry
    Thanks
    Jerry
    Jerry Woodstock

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362
    I'm not sure I understand your problem, but

    For regular old MDI forms,

    You need to create an MDI Form, then all forms that you want to be within this form, set their property MDIChild to true.

    The MDI parent will process all its code, and a child wont start until you load it!

    If you have code that you need to process before the parent loads, why dont you put it in a code module in Sub Main() ?

    You might already know this, but incase you dont.
    Hope this helps you
    Last edited by HairyMonkeyMan; April 28th, 2004 at 02:12 PM.

  3. #3
    Join Date
    Jan 2003
    Posts
    25
    Im sorry its hard to explain. here is a hypothetical example of what could happen.

    (Hypothetical Example)

    The Main Form has a very eloberate design and it contains multiple controls. buttons, textboxxes etc. If i push on a Button called load file It then Opens a Open Dialog. What i Need to do is prevent the Open Dialog from leaving the client area of the main form.

    Problem is
    1.) Controls Must stay on Main Form (wont work with aMDI form)
    2.) The Open File Dialog Must Stay Inside The Main Forms Client Area and Code needs to get input from Child Form Before The main form Can Continue Processing

    (End Hypothetical Example)

    I know people will say the open dialog is not a child form etc i just used it as a example of another form that might exist the keys here are

    1.) Forms Opened from Main form must be able to be dragged but not outside clien are of Main Form

    and

    2.) Main Form Execution Must wait on Data from Child Form


    Thanks again guys and gals
    Jerry
    Jerry Woodstock

  4. #4
    Join Date
    Dec 1999
    Posts
    128
    Hi Jerry

    Tough luck. I've had that problem since... i can't remember! It's a very big disadvantage of VB (up to VB6) that it doesn't allow modal MDIChild forms.

    I have two possible solutions to your problem. Both of them are not very elegant (programming-wise) but they'll do the job. Assume all created forms have MDIChild=True.

    1. Create a "FormLoad" sub which will do the following: load a form then disable the form that was previously active. Also, create a "FormUnLoad" which will unload the form passed as parameter and activate the previous form. Use only these two subs to load/unload forms in your application. I know it can be a nightmare in some occasions. I can only say i have implemented such a "nightmare" which works almost flawlesly.

    2. You probably want to display the second form from within a sub in another form. You could break your code in two parts. Do the first part up until showing the form (modeless) and then do nothing. When you decide you have finished with the process the second form should do, you could do the following: from form2, either call a public sub of form1 or activate a timer in form1 which will contain the rest of your code and then unload form2.

    I hope I helped a little. Good luck.
    -------------------------
    Nick A.

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