Electron入门——MessageBox使用方法

版权声明: https://blog.csdn.net/GISuuser/article/details/86704476

需要使用Electron的dialog弹出提示框,实现一点简单的确定取消操作,官方的API文档全英文的,比较难懂,这里自己实践一下。

代码:

const {dialog,shell,nativeImage} = require('electron');
 dialog.showMessageBox({
                type: "info",//图标类型
                title: "帮助",//信息提示框标题
                message: "GIS小博实验室出品,如需要帮助请联系QQ965894265",//信息提示框内容
                buttons: ["前往作者博客", "取消"],//下方显示的按钮
                icon:nativeImage.createFromPath("./icon/search-globe.png"),//图标
                cancelId:2//点击x号关闭返回值
            }, function (index) {
                if(index==0){//点击前往博客后,从本地浏览器打开博客地址
                    shell.openExternal('https://blog.csdn.net/gisuuser/')
                }
            })

这个过程中比较蒙的是怎么设置图标了,必须要使用nativeImage才能实现

效果图如下:

猜你喜欢

转载自blog.csdn.net/GISuuser/article/details/86704476