【问题标题】:How to set the width and height of the current window in electron如何在电子中设置当前窗口的宽度和高度
【发布时间】:2017-10-16 12:54:19
【问题描述】:

我在创建窗口时设置了窗口的宽度和高度,现在我想在调用 ipc 主进程时更改同一窗口的宽度和高度。 这是我的代码

function createWindow() {
  win = new BrowserWindow({
    width: 448, // here I have set the width and height
    height: 650,
    frame: false,
    transparent: true,
    minimizable: true,
    maximizable: true,
    closable: true,
  })

  win.loadURL(url.format({
    pathname: path.join(__dirname, './view/loginWindow.html'),
    protocol: 'file:',
    slashes: true
  }))

.....
....

现在我调用ipc方法

ipcMain.on('userRegLinkClicked', (event, data) => {
  win.setSize({
    width: 448,
    height: 850
  })
}  

但是没有任何效果,而是我收到错误TypeError: Error processing argument at index 0, conversion failure from #<Object>

【问题讨论】:

    标签: electron


    【解决方案1】:

    window.setSize 不采用带宽度/高度的选项对象,而是使用宽度/高度和附加参数作为直接参数。

    改用这个:

    ipcMain.on('userRegLinkClicked', (event, data) => {
      win.setSize(448, 850);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-24
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 2014-03-05
      相关资源
      最近更新 更多