mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Add support for WinForms DPI scaling
This commit is contained in:
parent
7a858ca08f
commit
078de51ce7
@ -1,4 +1,5 @@
|
||||
using Bloxstrap.Enums;
|
||||
using Bloxstrap.Helpers;
|
||||
|
||||
namespace Bloxstrap.Dialogs.BootstrapperDialogs
|
||||
{
|
||||
@ -59,6 +60,18 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
|
||||
}
|
||||
}
|
||||
|
||||
public void ScaleWindow()
|
||||
{
|
||||
this.Size = this.MinimumSize = this.MaximumSize = WindowScaling.GetScaledSize(this.Size);
|
||||
|
||||
foreach (Control control in this.Controls)
|
||||
{
|
||||
control.Size = WindowScaling.GetScaledSize(control.Size);
|
||||
control.Location = WindowScaling.GetScaledPoint(control.Location);
|
||||
control.Padding = WindowScaling.GetScaledPadding(control.Padding);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupDialog()
|
||||
{
|
||||
if (Program.IsQuiet)
|
||||
|
@ -35,6 +35,7 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
|
||||
|
||||
Bootstrapper = bootstrapper;
|
||||
|
||||
ScaleWindow();
|
||||
SetupDialog();
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
|
||||
// have to convert icon -> bitmap since winforms scaling is poop
|
||||
this.IconBox.Image = Program.Settings.BootstrapperIcon.GetIcon().ToBitmap();
|
||||
|
||||
ScaleWindow();
|
||||
SetupDialog();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
|
||||
|
37
Bloxstrap/Helpers/WindowScaling.cs
Normal file
37
Bloxstrap/Helpers/WindowScaling.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Bloxstrap.Helpers
|
||||
{
|
||||
public class WindowScaling
|
||||
{
|
||||
public static double GetFactor()
|
||||
{
|
||||
return Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;
|
||||
}
|
||||
|
||||
public static int GetScaledNumber(int number)
|
||||
{
|
||||
return (int)Math.Ceiling(number * GetFactor());
|
||||
}
|
||||
|
||||
public static System.Drawing.Size GetScaledSize(System.Drawing.Size size)
|
||||
{
|
||||
return new System.Drawing.Size(GetScaledNumber(size.Width), GetScaledNumber(size.Height));
|
||||
}
|
||||
|
||||
public static System.Drawing.Point GetScaledPoint(System.Drawing.Point point)
|
||||
{
|
||||
return new System.Drawing.Point(GetScaledNumber(point.X), GetScaledNumber(point.Y));
|
||||
}
|
||||
|
||||
public static Padding GetScaledPadding(Padding padding)
|
||||
{
|
||||
return new Padding(GetScaledNumber(padding.Left), GetScaledNumber(padding.Top), GetScaledNumber(padding.Right), GetScaledNumber(padding.Bottom));
|
||||
}
|
||||
}
|
||||
}
|
@ -132,7 +132,7 @@ namespace Bloxstrap
|
||||
|
||||
string commandLine = "";
|
||||
|
||||
#if false //DEBUG
|
||||
#if DEBUG
|
||||
new Preferences().ShowDialog();
|
||||
#else
|
||||
if (args.Length > 0)
|
||||
|
Loading…
Reference in New Issue
Block a user