У меня есть приложение с текстовым полем, и ширина текстового поля на экране всегда должна составлять 17,5 сантиметров на экране пользователя.
Это то, что я пробовал до сих пор:
const double centimeter = 17.5; // the width I need
const double inches = centimeter * 0.393700787; // convert centimeter to inches
float dpi = GetDpiX(); // get the dpi. 96 in my case.
var pixels = dpi*inches; // this should give me the amount of pixels
textbox1.Width = Convert.ToInt32(pixels); // set it. Done.
private float GetDpiX()
{
floar returnValue;
Graphics graphics = CreateGraphics();
returnValue = graphics.DpiX;
graphics.Dispose(); // don’t forget to release the unnecessary resources
return returnValue;
}
Но это дает мне разные размеры с разными разрешениями.
Это дает мне 13 см с 1680 x 1050 и 21,5 см с 1024 x 768 .
Что я делаю не так?