PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Click link open form and still access window from behind-VBForums
Results 1 to 4 of 4

Thread: Click link open form and still access window from behind

  1. #1

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    438

    Click link open form and still access window from behind

    Can't remember how to do this as I always wanted the form to be on top of everything so that you couldn't touch the other window from behind unless you closed the one on top.

    I am currently using this

    Code:
    new WhatsNew().ShowDialog();
    What do I need to do in order to display the window but also be able to click on the window behind that window please?

    Thanks

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,754

    Re: Click link open form and still access window from behind

    Firstly, that's bad code. Closing a form displayed using ShowDialog doesn't dispose it, so it is your responsibility to do the disposing. As with any short-lived, disposable objects, you should do that with a using block:
    csharp Code:
    1. using (var dialogue = new WhatsNew())
    2. {
    3.     dialogue.ShowDialog();
    4. }
    As for your question, you basically have four options for displaying a form:
    csharp Code:
    1. myForm.Show();
    2. myForm.Show(this);
    3. myForm.ShowDialog();
    4. myForm.ShowDialog(this);
    The ShowDialog method displays the form and prevents access to any other forms owned by the same thread, which generally means all forms. The Show method displays the form but does not prevent access to other forms, so that is what you want to be calling.

    By passing this as an argument, you make the current form the owner of the new form. If you call Show, that has the effect of creating a modeless dialogue. Unlike a modal dialogue, a modeless dialogue does not prevent access to other forms. It does prevent the dialogue being hidden behind its owner though. A modeless dialogue will also minimise, restore and close when its owner does. An example of where you might use a modeless dialogue is a Find & Replace window, where you would need to access the main document window without it covering the dialogue.

    I've never seen a situation where specifying an owner when calling ShowDialog is useful. That because the functionality of a modal dialogue overrides any functionality of a modeless dialogue. The only advantage it could provide is that you can access the caller via the Owner property but you can only access members of the Form type anyway, so it is of limited utility.

  3. #3

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    438

    Re: Click link open form and still access window from behind

    When I try to use your example above to just show the window using this

    Code:
    using (Database dialogue = new Database())
                {
                    dialogue.Show(this);
                }
    The window appears then disappears

    If I change it to
    Code:
    myForm.ShowDialog();
    for example, the window does appear.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,754

    Re: Click link open form and still access window from behind

    The point of a using statement is to dispose an object implicitly when you're finished using it. In this case, you're not finished using that form immediately after showing it so you don't use a using statement. I specifically said that forms displayed with ShowDialog aren't implicitly disposed when you close them. What is unsaid there is that forms displayed with Show are implicitly disposed when you close them, so there's no need for you to dispose them yourself.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width