Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how get dpi scale factor

how get dpi scale factor

Scheduled Pinned Locked Moved C#
15 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    hi all how i get the dpi scale factor is selected. thanks.

    V L J 4 Replies Last reply
    0
    • L Le rner

      hi all how i get the dpi scale factor is selected. thanks.

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Where are you going to get it from?

      1 Reply Last reply
      0
      • L Le rner

        hi all how i get the dpi scale factor is selected. thanks.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        DPI-related APIs and registry settings | Microsoft Docs[^]

        L 1 Reply Last reply
        0
        • L Lost User

          DPI-related APIs and registry settings | Microsoft Docs[^]

          L Offline
          L Offline
          Le rner
          wrote on last edited by
          #4

          var graphics = control.CreateGraphics()) int dpi_scale_val= graphics.DpiX; but it always return 96

          L 1 Reply Last reply
          0
          • L Le rner

            var graphics = control.CreateGraphics()) int dpi_scale_val= graphics.DpiX; but it always return 96

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Le@rner wrote:

            but it always return 96

            That is correct.

            L 1 Reply Last reply
            0
            • L Lost User

              Le@rner wrote:

              but it always return 96

              That is correct.

              L Offline
              L Offline
              Le rner
              wrote on last edited by
              #6

              i have 4k laptop its by default resolution is 200%

              L D 3 Replies Last reply
              0
              • L Le rner

                i have 4k laptop its by default resolution is 200%

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                If you want help with a programming question, you really need to provide proper details, rather than vague statements.

                L 1 Reply Last reply
                0
                • L Le rner

                  hi all how i get the dpi scale factor is selected. thanks.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Name of the school/uni?

                  Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  1 Reply Last reply
                  0
                  • L Lost User

                    If you want help with a programming question, you really need to provide proper details, rather than vague statements.

                    L Offline
                    L Offline
                    Le rner
                    wrote on last edited by
                    #9

                    ok sorry

                    1 Reply Last reply
                    0
                    • L Le rner

                      i have 4k laptop its by default resolution is 200%

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      See the section headed DPI Unaware at High DPI Desktop Application Development on Windows - Win32 apps | Microsoft Docs[^]

                      1 Reply Last reply
                      0
                      • L Le rner

                        i have 4k laptop its by default resolution is 200%

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #11

                        "200%" is not a resolution. It's a scaling factor used to enlarge text when displayed. The display dpi is still 96. One has nothing to do with the other.

                        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                        Dave Kreskowiak

                        L 1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          "200%" is not a resolution. It's a scaling factor used to enlarge text when displayed. The display dpi is still 96. One has nothing to do with the other.

                          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                          Dave Kreskowiak

                          L Offline
                          L Offline
                          Le rner
                          wrote on last edited by
                          #12

                          yes i want this scaling factor in c#

                          D 1 Reply Last reply
                          0
                          • L Le rner

                            hi all how i get the dpi scale factor is selected. thanks.

                            J Offline
                            J Offline
                            JudyL_MD
                            wrote on last edited by
                            #13

                            DPI scaling is not that simple. Here's how I do it for WinForms apps: First, your app needs to be DPI-aware. You set that by the manifest. You also set that with with the AutoScaleDimensions and AutoScaleMode properties on each form. Second, if you're designing forms from within Visual Studio, you need to do it on a system that is using 100% as the scaling factor for the display. If you don't do this, step 3 doesn't work. Third, you can now use

                            scaleFrom96 = this.DeviceDpi / 96.0

                            to calculate a multiplication factor for resizing those things manually that WinForms will not do for you. Be warned, it is very hit and miss what things will be scaled for you automatically and what things will not. Lots of testing required. OR you punt it all and design on a system that matches the system the app will be running on. Judy

                            Be wary of strong drink. It can make you shoot at tax collectors - and miss. Lazarus Long, "Time Enough For Love" by Robert A. Heinlein

                            L 1 Reply Last reply
                            0
                            • L Le rner

                              yes i want this scaling factor in c#

                              D Offline
                              D Offline
                              Dave Kreskowiak
                              wrote on last edited by
                              #14

                              OK, what for?

                              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                              Dave Kreskowiak

                              1 Reply Last reply
                              0
                              • J JudyL_MD

                                DPI scaling is not that simple. Here's how I do it for WinForms apps: First, your app needs to be DPI-aware. You set that by the manifest. You also set that with with the AutoScaleDimensions and AutoScaleMode properties on each form. Second, if you're designing forms from within Visual Studio, you need to do it on a system that is using 100% as the scaling factor for the display. If you don't do this, step 3 doesn't work. Third, you can now use

                                scaleFrom96 = this.DeviceDpi / 96.0

                                to calculate a multiplication factor for resizing those things manually that WinForms will not do for you. Be warned, it is very hit and miss what things will be scaled for you automatically and what things will not. Lots of testing required. OR you punt it all and design on a system that matches the system the app will be running on. Judy

                                Be wary of strong drink. It can make you shoot at tax collectors - and miss. Lazarus Long, "Time Enough For Love" by Robert A. Heinlein

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                Judy, Great answer, I hope to see you answering more C# related questions in the future. :) The Windows API equivalent to what you are doing there would be calling the GetDpiForMonitor function[^] and obtaining the MDT_EFFECTIVE_DPI[^] value and dividing by the system default. Of course the operating system hides dpi/scaling values from threads unless it's DPI aware[^]. So the caller needs to set thread DPI awareness before performing the calculation. I'd like to add that GetScaleFactorForMonitor[^] may return incorrect values. The manual calculation is preferred. I'd also like to add that the process doesn't necessarily need to be DPI aware. Beginning with Win10 1607 you can create a DPI aware thread to get those values by using the SetThreadDpiAwarenessContext function[^]. Hope to see you answering more often! Best Wishes, -David Delaune

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups