开发者

How to open a same window as childwindow and when closed enable parent window?

I have a window that opens a pop up and what i want is open the popup as child window or window on top of another and disable the back window? so that somebody cannot go back and close the Main window.

I tried putting the window top most but still i am able to close the main window.

private void axWebBrowser1_NewWindow3(object sender, DWebBrowserEvents2_NewWindow2Event e)
{
    BrowserWindow window = new BrowserWindow();
    window.axWebBrowser1.RegisterAsBrowser = true;
    window.Visibility = Visibility.Visible;
    window.textBox.IsEnabled = false;
    window.Height = 550;
    window.Width = 600;
    e.ppDisp = window.axWebBrowser1.Application;
    wi开发者_高级运维ndow.Topmost = true;            
}


Does setting the owner of the child window help?

private void axWebBrowser1_NewWindow3(object sender, DWebBrowserEvents2_NewWindow2Event e)
{
    BrowserWindow window = new BrowserWindow();
    window.Owner = this;
    ...          
}


When you display the child window, display it as a modal window, using the Form.ShowDialog Method. There's no need to disable the parent window then, as the child window being shown as a modal window would make the parent window not accessible until the modal window is closed.

BrowserWindow window = new BrowserWindow();
window.ShowDialog();

If modal doesn't work for you for some reason try something like this. I'm unsure of why you can't use modal, need to understand your requirement a little more.

private void axWebBrowser1_NewWindow3(object sender, DWebBrowserEvents2_NewWindow2Event e)
{
    BrowserWindow window = new BrowserWindow();

    // in your case I think the parent form should be = this.
    Form parentForm = this;    
    window.Tag = parentForm;
    window.FormClosing += new FormClosingEventHandler(this.BrowserWindow_FormClosing);

    parentForm.Enabled = false;
}

private void BrowserWindow_FormClosing(object sender, FormClosingEventArgs e)
{
    Form parentWindow = (sender as Form).Tag;
    parentWindow.Enabled = true;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜