2
I need to place a button with height and width in centimeters, where the size is maintained if accessed in different screen resolutions. Is that possible? If so, how?
2
I need to place a button with height and width in centimeters, where the size is maintained if accessed in different screen resolutions. Is that possible? If so, how?
3
It is impossible to do this. There is no way to do it because there is no way to do it reliably.
Some people use a way of calculating the configured DPI, but this does not reproduce the actual monitor interface.
The WPF tried to do this but the results are inaccurate and in the background does not fulfill what promises.
In that answer in the OS can do the conversion if you want to insist, but do not say that I did not warn that it does not work:
int CentimeterToPixel(double centimeter) {
double pixel = -1;
using var g = this.CreateGraphics())
pixel = centimeter * g.DpiY / 2.54d;
return (int)pixel;
}
I put in the Github for future reference.
In general this is not even a good idea. Each person has a different need for visualization. Size in centimeters can be good for paper, not for canvas.
I’ve used C# 8 syntax.
Browser other questions tagged c# .net winforms button
You are not signed in. Login or sign up in order to post.