Click here to Skip to main content
15,917,991 members
Home / Discussions / C#
   

C#

 
GeneralRe: create our own unit testing framework in C# Pin
mtoha13-Apr-23 16:39
professionalmtoha13-Apr-23 16:39 
QuestionManagement of window coordinates and sizes for multiple screens of different resolutions Pin
temuco25-Mar-23 13:14
professionaltemuco25-Mar-23 13:14 
AnswerRe: Management of window coordinates and sizes for multiple screens of different resolutions Pin
OriginalGriff25-Mar-23 20:18
mveOriginalGriff25-Mar-23 20:18 
GeneralRe: Management of window coordinates and sizes for multiple screens of different resolutions Pin
temuco26-Mar-23 1:22
professionaltemuco26-Mar-23 1:22 
GeneralRe: Management of window coordinates and sizes for multiple screens of different resolutions Pin
Dave Kreskowiak26-Mar-23 5:38
mveDave Kreskowiak26-Mar-23 5:38 
GeneralRe: Management of window coordinates and sizes for multiple screens of different resolutions Pin
temuco26-Mar-23 22:28
professionaltemuco26-Mar-23 22:28 
GeneralRe: Management of window coordinates and sizes for multiple screens of different resolutions Pin
Dave Kreskowiak27-Mar-23 1:30
mveDave Kreskowiak27-Mar-23 1:30 
GeneralRe: Management of window coordinates and sizes for multiple screens of different resolutions Pin
temuco27-Mar-23 21:18
professionaltemuco27-Mar-23 21:18 
Yes.

I have looked into the subject more closely. Here I find that Windows always ensures that the dpi number remains the same with different scaling. To do this, Windows changes the number of pixels. Here is an example from my Dell XPS with 3840x2400 pixels: with a scaling of 175%, Windows calculates with a screen resolution of 2194x1371. This means that the scaling at this resolution remains 100% at 96 dpi.

Nevertheless, our old software gets confused with this. I assume that it calculates the scaling factor internally incorrectly - actually, this should not be taken into account at all as long as Windows programmatically delivers a scaling of 100% at 96 dpi.

Here is a programme code that shows me (and confirms) everything essential in the debugger:

C#
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace multimonitor1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Abrufen der DPI-Skalierung und Skalierungsstufe jedes Bildschirms
            List<(float, float, int)> screenDpiScales = new List<(float, float, int)>();

            while (true)
            {
                foreach (Screen screen in Screen.AllScreens)
                {
                    using (var form = new Form() { Bounds = screen.Bounds, TopMost = true })
                    {
                        form.Show();

                        Graphics g = Graphics.FromHwnd(form.Handle);

                        float	dpiX	= g.DpiX;
                        float	dpiY	= g.DpiY;
                        int		scale	= (int) Math.Round(dpiX / 96.0 * 100);
                        
						screenDpiScales.Add((dpiX, dpiY, scale));
                        
						form.Hide();
                    }
                }

                // Ermitteln der Größe und Position der Anwendung
                int appLeft		= 0;
                int appTop		= 0;
                int appWidth	= 0;
                int appHeight	= 0;

                // Hier müssen die genauen Koordinaten der Anwendung in Bezug auf den Bildschirm ermittelt werden.
                // *** [English] The exact coordinates of the application in relation to the screen must be determined here. ***

                // Berechnen der Größe und Position der Anwendung auf jedem Bildschirm
                for (int i = 0; i < Screen.AllScreens.Length; i++)
                {
                    Screen screen = Screen.AllScreens[i];

                    (float, float, int) dpiScale = screenDpiScales[i];

                    Rectangle screenBounds = screen.Bounds;

                    float	dpiX	= dpiScale.Item1;
                    float	dpiY	= dpiScale.Item2;
                    int		scale	= dpiScale.Item3;

                    appLeft		= (int) (appLeft	* screenBounds.Width	/ (dpiX / 96.0 * scale));
                    appTop		= (int) (appTop		* screenBounds.Height	/ (dpiY / 96.0 * scale));
                    appWidth	= (int) (appWidth	* screenBounds.Width	/ (dpiX / 96.0 * scale));
                    appHeight	= (int) (appHeight	* screenBounds.Height	/ (dpiY / 96.0 * scale));

                    // Ausgabe der Größe und Position der Anwendung
                    Console.WriteLine($"Left:   {appLeft}");
                    Console.WriteLine($"Top:    {appTop}");
                    Console.WriteLine($"Width:  {appWidth}");
                    Console.WriteLine($"Height: {appHeight}");
                }

                Console.ReadLine();
            }
        }
    }
}

This solves the case for me.

Many thanks and best regards

René
GeneralRe: Management of window coordinates and sizes for multiple screens of different resolutions Pin
Gerry Schmitz26-Mar-23 7:57
mveGerry Schmitz26-Mar-23 7:57 
QuestionEntity Framework Code First - two Foreign Keys from same table Pin
Alex Dunlop21-Mar-23 8:43
Alex Dunlop21-Mar-23 8:43 
AnswerRe: Entity Framework Code First - two Foreign Keys from same table Pin
Gerry Schmitz21-Mar-23 9:30
mveGerry Schmitz21-Mar-23 9:30 
AnswerRe: Entity Framework Code First - two Foreign Keys from same table Pin
jschell23-Mar-23 6:04
jschell23-Mar-23 6:04 
AnswerRe: Entity Framework Code First - two Foreign Keys from same table Pin
Richard Deeming27-Mar-23 0:35
mveRichard Deeming27-Mar-23 0:35 
QuestionHow to highlight all rows in listbox between two index values? Pin
Member 1405587917-Mar-23 1:25
Member 1405587917-Mar-23 1:25 
AnswerRe: How to highlight all rows in listbox between two index values? Pin
Pete O'Hanlon17-Mar-23 1:33
mvePete O'Hanlon17-Mar-23 1:33 
AnswerRe: How to highlight all rows in listbox between two index values? Pin
RedDk17-Mar-23 6:26
RedDk17-Mar-23 6:26 
QuestionMessage Closed Pin
15-Mar-23 20:32
Sivanujan Sivaraja15-Mar-23 20:32 
AnswerRe: Serial port listening application Pin
OriginalGriff15-Mar-23 21:02
mveOriginalGriff15-Mar-23 21:02 
GeneralRe: Serial port listening application Pin
Richard MacCutchan15-Mar-23 22:34
mveRichard MacCutchan15-Mar-23 22:34 
GeneralRe: Serial port listening application Pin
OriginalGriff15-Mar-23 22:41
mveOriginalGriff15-Mar-23 22:41 
GeneralRe: Serial port listening application Pin
Pete O'Hanlon16-Mar-23 0:19
mvePete O'Hanlon16-Mar-23 0:19 
GeneralRe: Serial port listening application Pin
OriginalGriff16-Mar-23 1:17
mveOriginalGriff16-Mar-23 1:17 
GeneralRe: Serial port listening application Pin
Pete O'Hanlon16-Mar-23 6:11
mvePete O'Hanlon16-Mar-23 6:11 
GeneralRe: Serial port listening application Pin
Dave Kreskowiak16-Mar-23 6:21
mveDave Kreskowiak16-Mar-23 6:21 
QuestionDownloading & Executing an Installer - User Cancels Pin
Kevin Marois13-Mar-23 12:52
professionalKevin Marois13-Mar-23 12:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.