在创建窗口的时候添加几个属性:
width:窗口宽度
height:窗口高度
minWidth:窗口最小宽度
maxWidth:窗口最大宽度
minHeight:窗口最小高度
maxHeight:窗口最大高度
x:指定窗口的横坐标
y:指定窗口的纵坐标
height:窗口高度
minWidth:窗口最小宽度
maxWidth:窗口最大宽度
minHeight:窗口最小高度
maxHeight:窗口最大高度
x:指定窗口的横坐标
y:指定窗口的纵坐标
例子如下:
const {app,BrowserWindow} = require('electron')
function createWindow(){
win = new BrowserWindow({
width:800,
height:600,
minWidth:400,
minHeight:400,
maxWidth:800,
maxHeight:600,
x:20,
y:40,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html');
win.on('closed',()=>{
console.log('closed');
win = null;
});
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
console.log('window-all-closed');
if(process.platform != 'darwin'){
app.quit();
}
});
app.on('activate',()=>{
console.log('activate');
if(win == null) {
createWindow();
}
});
function createWindow(){
win = new BrowserWindow({
width:800,
height:600,
minWidth:400,
minHeight:400,
maxWidth:800,
maxHeight:600,
x:20,
y:40,
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html');
win.on('closed',()=>{
console.log('closed');
win = null;
});
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
console.log('window-all-closed');
if(process.platform != 'darwin'){
app.quit();
}
});
app.on('activate',()=>{
console.log('activate');
if(win == null) {
createWindow();
}
});