electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用

electron BrowserWindow min height and width not working after hide() show() methods

本文关键字:hide show 方法 不起作用 之后 BrowserWindow 小高 高度 electronic      更新时间:2023-09-26

1.步骤

mainWindow = new BrowserWindow({
  width: 1200,
  height: 700,
  center: true,
  'min-height': 700,
  'min-width': 1200,
  webPreferences: {nodeIntegration:true}});
mainWindow.loadURL(HOME_URL);

2.步骤(发生了一些事件,我想暂时隐藏主窗口并显示另一个(createFacebookWindow()fn已经加载URL)

mainWindow.hide();

facebookWindow = require('./modules/auth/views.js').createFacebookWindow();
FB Window settings ({
                                              width: 1200,
                                              height: 700,
                                              center: true,
                                              'min-height': 700,
                                              'min-width': 1200,
                                               webPreferences: {nodeIntegration:false}})

3.步骤(另一个事件发生i破坏fb窗口并显示主窗口)

 facebookWindow.close();
 facebookWindow.on('closed', function() {
    facebookWindow = null;
    mainWindow.show();
    //I tried below options it doesn't work
    //mainWindow.setSize(1200, 700);
    //mainWindow.setMinimumSize(1200, 700);

摘要:

所以实际上,在这些步骤之后,当我显示mainWindow时,它不记得mainWindow设置的最小高度和最小宽度不起作用。

当facebookWindow没有打开时,一切都很好,所以在切换窗口的过程中一定会发生一些事情。也许有些事情是按错误的顺序做的?

您可以在此处阅读BrowserWindow文档:https://github.com/electron/electron/blob/master/docs/api/browser-window.md

  • maxWidth而不是max-width
  • minWidth代替min-width

  • maxHeight代替max-height

  • minHeight而不是min-height

您可以在初始化BrowserWindow时添加minWidth: 500,如下所示:

function createWindow () {
  // Create the browser window.
  const win = new BrowserWindow({
    backgroundColor: '#ffffff',
    width: 1024,
    height: 768,
    minWidth:500,
    webPreferences: {
      nodeIntegration: true
    }
  })
}

注意:函数createWindow位于main.js文件中,因此只需在函数中添加minWidth: value即可。