【问题标题】:Why is BrowserWindow.setSize / setBounds / setContentBounds / setMaximumSize / setContentSize not working correctly in electron app?为什么 BrowserWindow.setSize / setBounds / setContentBounds / setMaximumSize / setContentSize 在电子应用程序中无法正常工作?
【发布时间】:2023-02-14 19:22:27
【问题描述】:

在代码中:

 let win: BrowserWindow;
    ....
    win.setSize(width, height);
    win.setPosition(x, y, false);
    win.setBounds({
          height
          width
          x,
          y,
        });

数据:

{ x: 1578, y: 915, width: 342, height: 125 }

但结果是:

但是为什么会出现如图这样的结果呢?由于某种原因宽度变成了410!我问342,请帮帮我

【问题讨论】:

    标签: electron


    【解决方案1】:

    您不需要使用 .setSize 或 .setPosition,.setBounds 设置位置和大小...

    .setBounds 参数(看起来你有一些语法错误)是一个矩形,其参数值按 x、y、宽度、高度的顺序排列。除非您明确指定参数名称和值。

    您可以使用 .setBounds 设置窗口位置:

        win.setBounds({
              x: 1578,
              y: 915,
              width: 342,
              height: 125
            });
    

    【讨论】:

      【解决方案2】:

      Electron 方面有一个问题,当屏幕分辨率为奇数时,如 125%,它会随机调整像素。检查链接 https://github.com/electron/electron/issues/27651

      【讨论】:

        猜你喜欢
        • 2016-12-12
        • 1970-01-01
        • 1970-01-01
        • 2021-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-08
        • 1970-01-01
        相关资源
        最近更新 更多