如何使用 Electron.js 显示彼此相邻的自定义 Windows 消息框按钮

How to show custom Windows message box buttons next to each other using Electron.js

我正在尝试使用 Electron.js 对话框方法 showMessageBoxSync 创建一个消息框。我希望按钮为 'Cancel' 和 'Overwrite and Continue'。当按钮为 'Cancel' 和 'OK'.

时,我希望它以与框相同的方式显示

当按钮为'Cancel'和'OK'时,按钮并排显示:

然而,当我尝试将按钮设置为 'Cancel' 和 'Overwrite and Continue' 时,消息框显示不同:

是否可以将'Overwrite and Continue'按钮设置为与'OK'按钮相同的显示方式?

我的消息框代码是:

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
})

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

noLink Boolean (optional) - On Windows Electron will try to figure out which one of the buttons are common buttons (like "Cancel" or "Yes"), and show the others as command links in the dialog. This can make the dialog appear in the style of modern Windows apps. If you don't like this behavior, you can set noLink to true.

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