Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm making a program where I would like to work with 300 PPI, but when I use the property of "screen.BitsPerPixel.ToString ())" to check the PPI, the result is 32 only, but this property is just get

What I have tried:

I don't know where can i change it ... would anyone know to inform me?
Posted
Updated 2-Mar-20 17:03pm

In case you need really to change the resolution (for which I can imagine only very very view cases), follow this accepted solution here: How to change screen resolution in C #?[^]
 
Share this answer
 
v2
Comments
Sergey Bebenin 17-Dec-20 16:03pm    
Thanks!
Question though... this example
https://www.codeproject.com/Articles/36664/Changing-Display-Settings-Programmatically

doesn't keep res. change indefinitely. It only changes it for the current session and it doesn't stick on reboot.
Any idea what needs to be set to keep it indefinitely? Maybe something is different on Win10.
I compared registry (manual set vs. programmatic set) and it's bunch of extra gibberish in Display Driver section which seems to do it when done manually.

Edit: Found the issue...
ChangeDisplaySettings
dwflags should be set to 1
BitsPerPixel has nothing to do with PPI (points per inch). It is the number of bits used to represent color information for a single pixel in an image.

Changing screen resolution for any reason is a really bad idea and likely to get your software uninstalled the very first time you try to do it.
 
Share this answer
 
Comments
[no name] 2-Mar-20 12:07pm    
Oh what the f... whatever, I read PPI as Pixel Per Inch, please skip my answer :)
João Henrique Braga 2-Mar-20 16:17pm    
I understand, how would I have access to the Pixel Per Inch information that is being used in the program? because I need to know it to convert real measurements (meters) to fictitious measurements (Pixel)
Well, you can try working with the other various properties of both the Screen and SystemParameters classes to get the resolution and density
C#
int DPI = Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;
Now changing it to 300 seems to be unworkable/unreasonable.... A 4K monitor running at that density would only be a 15" diagonal screen

You may also want to do some research on DPI Awareness, as it could be of use to you.

References:
Screen.PrimaryScreen Property (System.Windows.Forms) | Microsoft Docs[^]
SystemParameters Class (System.Windows) | Microsoft Docs[^]
Pixel Density and Usability | Microsoft Docs[^]
 
Share this answer
 
Comments
João Henrique Braga 4-Mar-20 8:40am    
the command did not compile "SystemParameters.PrimaryScreenWidth;"
but I still have the doubt about how I can make a drawing by the computer and be able to print in scale, you understand my doubt ?? I want to make a line that is exactly 15 centimeters, for example, through the code.
MadMyche 4-Mar-20 14:41pm    
You just brought something forward which is COMPLETELY MISSING from your question- that you are intending this for PRINT which is completely different than screen resolution.
João Henrique Braga 4-Mar-20 18:55pm    
ok, thankyou for your help.
Quote:
I don't know where can i change it ... would anyone know to inform me?

Bad idea !
Only a few advices.
Every client will have excellent reasons to have its screen set as it is:
- Screen size
- Screen resolution
- Impaired eyes
- Other apps running on screen
- Changing screen resolution is changing desk size and can end up with messing icons positions.
- ...

The only sensible thing to do is to scale your app display in its window. And probably provide a zoom tool so that the client can change scale as he sees fit (See how zoom works in Excel).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900