user1234
user1234

Reputation: 8978

How do I re-center an electron window after dynamically resizing?

After calling

remote.getCurrentWindow().setSize(width, height);

the window resizes, but is not positioned in the center of the screen. Is there a way to adjust the offset of the window relative to the screen?

Upvotes: 6

Views: 7469

Answers (1)

user1234
user1234

Reputation: 8978

There is a .center() method on BrowserWindow, so

const win = remote.getCurrentWindow();
win.setSize(width, height);
win.center();

centers the window after resizing.

Upvotes: 22

Related Questions