问题描述
场景
我有一个窗口,它有一个打开一个窗口的添加任务按钮
.每次用户点击它,它都会打开一个窗口.我在 add task window
上有一个按钮,可以将其最小化.这个最小化按钮如何实现?
I have a window and it has an add task button
that is opening a window. Everytime user clicks on it, it opens a window. I have a button on add task window
that minimize it. How to implement this minimize button?
代码
我可以使用以下代码关闭
最大化
窗口:
I am able to close
maximize
window by using the code below:
var winclose = function () {
window.close();
}
var winmaximize = function () {
window.moveTo(0, 0);
window.resizeTo(screen.width, screen.height);
}
但是,我找不到任何可以从渲染进程中最小化窗口的函数.
However, I am not able to find any function that can minimize a window from rendered process.
请帮忙,非常感谢;
注意:
浏览器不向开发者提供最小化它们的功能.但在这儿是一个不同的场景.这里我使用的是 Electronjs 提供的铬.因此,在我们开发桌面应用程序时,一定有办法做到这一点
虚拟下载链接:从 OneDrive 下载
推荐答案
可以调用minimize()
在相应的 BrowserWindow
实例上.问题是如何最好地访问此实例,而这又取决于您打开窗口的方式以及最小化按钮的位置.从您的示例中,我认为最小化按钮实际上位于您要关闭的窗口中,在这种情况下,您可以最小化焦点窗口,因为当用户单击其中的按钮时,窗口当前应该具有焦点:
You can call minimize()
on the respective BrowserWindow
instance. The question is how to best get access to this instance and this, in turn, depends on how you open the windows and where your minimize button is. From your example, I take it that the minimize button is actually in the window you want to close, in that case you can just minimize the focused window, because to when a user clicks the button inside it, the window should currently have the focus:
const { remote } = require('electron')
remote.BrowserWindow.getFocusedWindow().minimize();
您也可以使用 BrowserWindow.fromId()
来访问相关窗口,例如,如果您想从另一个窗口最小化任务窗口.
Alternatively you can use BrowserWindow.fromId()
to get access to the window in question if, for example, you want to minimize the task window from the other window.
这篇关于Electron:如何最小化渲染进程中的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!