【问题标题】:How to show custom Windows message box buttons next to each other using Electron.js如何使用 Electron.js 彼此相邻显示自定义 Windows 消息框按钮
【发布时间】:2021-02-20 13:36:33
【问题描述】:

我正在尝试使用 Electron.js 对话框方法 showMessageBoxSync 创建一个消息框。我希望按钮是“取消”和“覆盖并继续”。我希望它以与按钮为“取消”和“确定”时的框相同的方式显示。

当按钮为“取消”和“确定”时,按钮并排显示:

但是,当我尝试将按钮设置为“取消”和“覆盖并继续”时,消息框的显示方式不同:

是否可以将“覆盖并继续”按钮设置为与“确定”按钮相同的显示方式?

我的消息框代码是:

const userSelection = dialog.showMessageBoxSync(mainWindow, {
    type: 'warning',
    title: 'User data already exists in this location',
    message: 'User data for the App already exists in this location. Do you want to overwrite it?',
    buttons: ['Cancel', 'Overwrite and Continue'],
    defaultId: 0,
    cancelId: 0
})

【问题讨论】:

    标签: javascript node.js windows electron messagebox


    【解决方案1】:

    您必须使用docs 中描述的noLink 属性:

    noLink 布尔值(可选)- 在 Windows Electron 上,将尝试找出 buttons 中的哪一个是常用按钮(如“取消”或“是”),并将其他按钮显示为对话框中的命令链接.这可以使对话框以现代 Windows 应用程序的样式出现。如果您不喜欢这种行为,可以将 noLink 设置为 true。

    因此,在您的情况下,您需要将 noLink: true 添加到您的选项对象中。

    【讨论】:

    • 不知道我是如何在文档中错过的 - 非常感谢 :)
    猜你喜欢
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2014-08-23
    • 2020-04-27
    相关资源
    最近更新 更多