Click here to Skip to main content
15,891,529 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# List of Tasks Pin
OriginalGriff6-Apr-23 21:50
mveOriginalGriff6-Apr-23 21:50 
GeneralRe: C# List of Tasks Pin
OriginalGriff6-Apr-23 21:58
mveOriginalGriff6-Apr-23 21:58 
AnswerRe: C# List of Tasks Pin
lmoelleb7-Apr-23 1:54
lmoelleb7-Apr-23 1:54 
AnswerRe: C# List of Tasks Pin
jschell7-Apr-23 9:20
jschell7-Apr-23 9:20 
AnswerRe: C# List of Tasks Pin
Richard Deeming10-Apr-23 21:27
mveRichard Deeming10-Apr-23 21:27 
QuestionPassword Regex Help Pin
Jassim Rahma28-Mar-23 9:41
Jassim Rahma28-Mar-23 9:41 
AnswerRe: Password Regex Help Pin
Dave Kreskowiak28-Mar-23 11:21
mveDave Kreskowiak28-Mar-23 11:21 
AnswerRe: Password Regex Help Pin
OriginalGriff28-Mar-23 19:55
mveOriginalGriff28-Mar-23 19:55 
AnswerRe: Password Regex Help Pin
Eddy Vluggen1-Apr-23 6:31
professionalEddy Vluggen1-Apr-23 6:31 
AnswerRe: Password Regex Help Pin
Member 115612953-Apr-23 23:50
Member 115612953-Apr-23 23:50 
QuestionRe: Password Regex Help Pin
Eddy Vluggen14-Apr-23 6:41
professionalEddy Vluggen14-Apr-23 6:41 
AnswerRe: Password Regex Help Pin
Ravi Bhavnani15-Apr-23 10:52
professionalRavi Bhavnani15-Apr-23 10:52 
AnswerRe: Password Regex Help Pin
Bohdan Stupak19-Apr-23 3:28
professionalBohdan Stupak19-Apr-23 3:28 
Questioncreate our own unit testing framework in C# Pin
Sakhalean26-Mar-23 18:32
Sakhalean26-Mar-23 18:32 
AnswerRe: create our own unit testing framework in C# Pin
OriginalGriff26-Mar-23 21:00
mveOriginalGriff26-Mar-23 21:00 
AnswerRe: create our own unit testing framework in C# Pin
jschell27-Mar-23 7:00
jschell27-Mar-23 7:00 
AnswerRe: create our own unit testing framework in C# Pin
Gerry Schmitz27-Mar-23 11:39
mveGerry Schmitz27-Mar-23 11:39 
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é

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.