简体   繁体   English

C#绘制具有精度坐标的矩形。 怎么样?

[英]C# drawing Rectangle with precision coordinates. How?

How do I draw a Rectangle in C# with precision coordinates? 如何在C#中使用精度坐标绘制矩形?

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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