简体   繁体   中英

VB.NET: How to close and re-open a dialog in this case?

I'm developing a WinForms app in VB.NET, that handles sets of style data, and when the user clicks on another set's label, it prompts through a dialog "You are leaving this style preset to edit another one. keep changes on this one? [Yes] [No]"

But, I'm facing the problem that, when the user clicks either option, and the dialog closes, everything has to be refreshed, and loading the form again seems a good option.

I've tried putting a public sub on a module, that does this:

Public Sub CloseOpenStyleDlg()
    KeepOrDiscardPrompt.Close()
    StylesDlg.Close()
    StylesDlg.ShowDialog()
End Sub

But as soon as that sub is called from the prompt, it crashes the application. (doesn't show an error in debug, simply crashes) How should I, from a given dialog, close the dialog, it's parent, and re-open it's parent? (which triggers all the Dialog_Load() code of the parent)

Thanks in advance! :)

You need to instantiate the dialog again. If I take your code for example:

Public Sub CloseOpenStyleDlg()
    KeepOrDiscardPrompt.Close()
    StylesDlg.Close()
    StylesDlg = new StylesDlg()
    StylesDlg.ShowDialog()
End Sub

When a form is closed, all resources created within the object are closed and the form is disposed.

If you want to reuse the Window instance use StylesDialog.Hide() function instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM