c# - Actual resolution of secondary screen for custom DPI -
i'm working on adaptation of application custom dpi values (windows scaling).
if i've understood correctly, scaling makes applications think, resolution smaller, is. example, having 125% scale, if have 1920x1080 resolution, actual size of maximized window 1536x864. , sure, may cause problems, if control sizes , positions code.
for now, i'm using next values positioning etc:
systemparameters.fullprimaryscreenwidth
,systemparameters.fullprimaryscreenheight
"virtual" (scaled) resolution;screen.primaryscreen.workingarea.width
,screen.primaryscreen.workingarea.height
original resolution;
from values, easy scaling value, can used in positioning , sizing.
but of values primary screen. if need positioning , sizing secondary screen, might have different actual (and, therefore, different "virtual") resolution?
for i'm getting screen this
var screen = screen.fromhandle(new system.windows.interop.windowinterophelper(application.current.mainwindow).handle);
which allows me actual resolution, using workingarea
rectangle. "virtual" resolution? there analog of systemparameters.fullprimaryscreenwidth
etc of screen aside of primary?
ps. know, scale shared, getting value primary screen, can use other screen, i'd know answer, if there direct variable values, anyway.
you may use following ratio
// calculates text size in main window (i.e. 100%, 125%,...) var ratio = math.max(screen.primaryscreen.workingarea.width / systemparameters.primaryscreenwidth, screen.primaryscreen.workingarea.height / systemparameters.primaryscreenheight);
for example, if you'd show maximized windows on screen, need use following rectangles (code app.xaml.cs):
foreach (var screen in screen.allscreens) { var mainviewmodel = container.resolve<imainwindowmodel>(); var window = new mainwindow(mainviewmodel); if (screen.primary) current.mainwindow = window; window.left = screen.workingarea.left / ratio; window.top = screen.workingarea.top / ratio; window.width = screen.workingarea.width / ratio; window.height = screen.workingarea.height / ratio; window.show(); window.windowstate = windowstate.maximized; }
in addition, may take @ post https://ireznykov.com/2017/01/13/wpf-windows-on-two-screens/, refers github sample application outputs maximized windows on screens.
Comments
Post a Comment