Link to home
Create AccountLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

Problem with the Z-Order?

WHile I stil have a modal window open I want to open a non-modal, which will persist after the modal is closed.  I do not make the modal the parent (I don't think), but the newly opened non-modal closes when the modal closes.

What might I be doing wrong??

thanks,
newbieweb
Avatar of nsanga
nsanga

non-modal dialogs close when the parent is closed.........
may be because the non-modal dialog object that you are creating is scoped to the calling method and when parent closes, the child also closes.....

you may try by defining a class with static member of type dialog which you want to open and try
Avatar of curiouswebster

ASKER

> you may try by defining a class with static member of type dialog which you want to open and try

Here's the dialog class.  What would I change to make it static as you described?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DMS
{
    public partial class BeverageWarning : System.Windows.Forms.Form
    {
        private Driver driver;
        private int secondsDelay;
        private TLDateTime lastRingTime;

        public Handles Handles { get { return driver.Handles; } }

        public BeverageWarning(Driver driver, int secondsDelay)
        {
            InitializeComponent();
            this.driver = driver;
            this.secondsDelay = secondsDelay;
            lastRingTime = new TLDateTime(driver.Handles);
        }

        private void closeBtn_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void BeverageWarning_Load(object sender, EventArgs e)
        {
            driverLabelLbl.Text = driver.DriverLabel;
            Handles.Preferences.Play("Beverage");
            InitTimer();
        }

        private void InitTimer()
        {
            this.timer = new System.Windows.Forms.Timer();
            this.timer.Tick += new EventHandler(OnTimerFiring);
            this.timer.Interval = secondsDelay * 1000;
            this.timer.Enabled = true;
        }

        private void OnTimerFiring(object sender, EventArgs e)
        {
            try
            {
                Close();
             }
            catch (Exception ex)
            {
                Handles.LogException("BeverageWarning.OnTimerFiring", ex, null);
            }
        }
    }
}
ASKER CERTIFIED SOLUTION
Avatar of nsanga
nsanga

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
In general, you should not open a non-modal window from a modal window - the non-modal 'child window' will go out of scope (and be closed) when the modal 'parent' is closed.  There is no way around this design behavior.  A modal window cannot leave something 'lying around', after it has been closed.

AW
I wasn't actually opening a non-modal from a modal.  Sorry for the confusion.

Instead, I was opening a non-modal from the method associated with the closing event of a modal dialog.  But regardless, the non-modal still closed when the modal was closed, which is why I thought I had an issue with the Z-order.

I've coded the static methodology, as suggested, and am about it test it.

Thanks,
newbieweb
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Yes I see that.  What I did was instead created a timer inside the code that was for the Modal dialog, upon closing.  It fires a second later and works great.

Thanks for the help.

newbieweb
ok, that gives tje modal window the time to close, before the non-modal window opens.  That would serve to break the relationship.


AW

Glad to be of assistance.