简体   繁体   中英

C# drawing Rectangle with precision coordinates. How?

How do I draw a Rectangle in C# with precision coordinates?

Example:

Rectangle test1 = new Rectangle(X, Y, Width, Height);

Width and Height values seem to have to be integers .

Is it possible to give Rectangle, inch size coordinates somehow?

Rectangle test2 = new Rectangle(100, 50, 1.93inches, 0.52inches);

Thanks for any help.

You'd have to convert know the conversion between inches and pixels, which depends on the screen resolution. I suppose you could do this:

Graphics graphics = this.CreateGraphics();
var dpiX = graphics.DpiX;
var dpiY = graphics.DpiY;
var rectangle = new Rectangle(100, 50, Math.Round(1.93 * dpiX), Math.Round(0.52 * dpiY));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM