【发布时间】:2017-11-16 20:40:12
【问题描述】:
我正在 window.js 中创建一个菜单,当我们点击它时,当前浏览器窗口的位置将会改变。我有我的 app.js 文件,我在其中创建了 browserWindow 并设置了 x,y 。现在如何更改当前 browserWindow 的 x,y 值?
我在 app.js 中的 BrowserWindow
window = new BrowserWindow({
width: 265,
height: screenheight,
x: screenXPosition,
y: 0,
icon: "icon.ico",
skipTaskbar: true,
alwaysOnTop: false,
show: false,
frame: false,
autoHideMenuBar: true,
transparent: true,
// resizable: false
})
我有一个 Window.js 文件,其中我的菜单是。是否需要将当前窗口实例传递给 window.js?如果是,我应该如何将当前的 browserWindow 实例传递给 window.js 到 app.js?我们如何改变 x,y 值? 可能吗 ? 我的 window.js 菜单
//Menu
const menu = new Menu()
// Build menu one item at a time, unlike
menu.append(new MenuItem({
label: 'Settings'
}))
menu.append(new MenuItem({
type: 'separator'
}))
menu.append(new MenuItem({
label: 'position',
submenu: [{
label: 'right',
role: '25%',
type: 'checkbox',
checked: true,
click: function () {
console.log('25%');
}
},
{
type: 'separator'
},
{
label: 'left',
role: '50%',
click: function () {
console.log('50%');
}
},
{
type: 'separator'
},
{
label: 'center',
role: '50%',
click: function () {
console.log('50%');
}
}
]
}))
window.addEventListener('contextmenu', (e) => {
e.preventDefault()
menu.popup(remote.getCurrentWindow())
}, false)
【问题讨论】: