问题描述
我正在尝试使用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
})
解决方法
您必须使用docs中所述的noLink
属性:
noLink
布尔值(可选)-在Windows上,Electron会尝试找出buttons
中的哪个是常用按钮(例如“取消”或“是”),并将其他按钮显示为命令对话框中的链接。这可以使对话框以现代Windows应用程序的样式显示。如果您不喜欢这种行为,可以将noLink设置为true。
因此,在您的情况下,您想将noLink: true
添加到选项对象。