Hello. From what I've understood the relationship point to pixel will depend on the screen resolution. So how can I calcule it at run-time in c#?
Thanks
Hello. From what I've understood the relationship point to pixel will depend on the screen resolution. So how can I calcule it at run-time in c#?
Thanks
It is all in Screen object
int bpp = System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel;
int wid = Screen.PrimaryScreen.WorkingArea.Width;
int ht = Screen.PrimaryScreen.WorkingArea.Height;
On my machine it gives:
bpp=32
width=1280
height=740
If you're trying to get the DPI of the screen it's a bit trickier. You'll have to create a real Graphics object and query that.
For example, in the Load event of your main form:
using( Graphics g = CreateGraphics() )
{
_dpiX = g.DpiX;
_dpiY = g.DpiY; // In practice usually == dpiX
_points = _dpiX / 72.0f; // There are 72 points per inch
}
Of course most monitors lie about the actual DPI and always return 72 or 96, or when large fonts are enabled 120. If you actually want to map a physical inch to a the screen you'll have to actually calibrate it with the user's help - having them pick a line that they measure to be 1 inch.