2

I'm using electron.Net, but when I start the main window, It always opens small size aligned to the center.

This is my code:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    if (env.IsDevelopment()) {
        app.UseDeveloperExceptionPage();
    } else {
        app.UseExceptionHandler("/Home/Error");
    }
    app.UseStaticFiles();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints => {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
    });

    Task.Run(async () => await Electron.WindowManager.CreateWindowAsync());

    Electron.Menu.SetApplicationMenu(new MenuItem[] {});
}
Raghul SK
  • 1,256
  • 5
  • 22
  • 30

1 Answers1

3

Based the BrowserWindow source and the Electron.NET Demo, the following one opens the Electron Window in the Maximized Window.

This just calls the BrowserWindow's Maximize() event manually just after showing the Window, when everything ready.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    if (env.IsDevelopment()) {
        app.UseDeveloperExceptionPage();
    } else {
        app.UseExceptionHandler("/Home/Error");
    }
    app.UseStaticFiles();

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints => {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
    });
    
    if (HybridSupport.IsElectronActive)
    {
        ElectronBootstrap();
    }
}

public async void ElectronBootstrap()
{
    var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
    {
        Width = 1152,
        Height = 940,
        Show = false
    });

    await browserWindow.WebContents.Session.ClearCacheAsync();

    // For the gracefull showing of the Electron Window when ready
    browserWindow.OnReadyToShow += () =>
    {
        browserWindow.Show();
        browserWindow.Maximize();
    }
    Electron.Menu.SetApplicationMenu(new MenuItem[] {});
} 

Hope this helps.

Sathish Guru V
  • 1,417
  • 2
  • 15
  • 39