Skip to content

How to prevent electron window closing when click close and ask confirmation #567

Closed
@soundararajans

Description

@soundararajans

How to prevent electron window closing when click close and ask confirmation

  • Node Version: V 14.17.0
  • Electron.Net Nuget: 11.5.1
  • Target: Win
  • .Net: Net5.0

I tried the below code. But it's not working and window is closing always without asking confirmation.

`
window.OnClose += () =>
{
MessageBoxOptions options = new MessageBoxOptions("Changes you made may not be saved");
options.Type = MessageBoxType.question;
options.Buttons = new string[] { "No", "Yes" };
options.DefaultId = 1;
options.CancelId = 0;

            if (Electron.Dialog.ShowMessageBoxAsync(options).Result.Response == 1)
            {
               
            }
        };

`

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions