System.Drawing.Rectangle 找不到“底部”的属性设置器或“左”或“右”或“顶部”

发布于 2024-12-06 22:51:40 字数 294 浏览 2 评论 0原文

在Delphi Prism中,我试图设置矩形属性,左,右,上或下,编译器一直说它找不到设置器来为矩形的这些属性设置值。

我查看了与此相关的其他 stackoverflow 问题,但没有找到好的答案。

我希望能够设置矩形的顶部、底部、右侧或左侧值,以便能够执行如下操作。

dragRect.right := dragRect.left;
dragRect.bottom := dragRect.top;

显然,你不能这样做。如何在 Delphi Prism 中完成同样的事情?

In Delphi Prism, I am trying to set the Rectangle properties, left right top or bottom, and compiler keeps saying that it can't find a setter to set a value to these properties for Rectangle.

I have looked at other stackoverflow questions related to this and have not found a good answer.

I want to be able to set the Rectangle it is top, bottom, right or left values to be able to do something like the following.

dragRect.right := dragRect.left;
dragRect.bottom := dragRect.top;

Obviously, you can't do this. How do you accomplish the samething in Delphi Prism?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

西瑶 2024-12-13 22:51:40

正如 Hans Passant 指出的那样,理解值类型和引用类型之间的区别很重要。由于 System.Drawing.Rectangle 没有左、上、右或下的设置器,因此您无法为它们设置任何值,而只能读取已有的值。
它们唯一更新的时间是当您实际创建 Rectangle 对象并传递高度、宽度和 XY 点或设置矩形属性的 X、Y、高度和/或宽度时。

因为在我的程序中我只是想定义绘制矩形形状的边界或区域,所以我设置了 X、Y、宽度或高度。效果很好。至于计算矩形的宽度和高度,一旦设置了其宽度和高度,就不必再计算了。每次重置矩形的 X 和/或 Y 值时,它都会保持其宽度和高度。因此,它知道它的右值和底值是什么。

例如,你可以这样做:

dragRect.X := 100;
dragRect.width := 10;

但你不能这样做:

dragRect.left := 100;
dragRect.right :=110;

As Hans Passant pointed out, it is important to understand the difference between value type and reference type. Because System.Drawing.Rectangle doesn't have setters for left, top, right or bottom, you simply can't set any values to them but only read what is already there.
The only time they get updated is when you actually create the Rectangle object passing the height, width and X-Y points OR setting X, Y, height and/or width of a rectangle properties.

Since in my program I am only trying to define the boundary or the area for drawing the shape of a rectangle, I set the X, Y, width or height. It works fine. As far as figuring out the width and height of a rectangle, you don't have to once you set its width and height once. Every time you reset the X and/or Y value of a rectangle, it maintains its width and height. Thus, it knows what its right and bottom values are.

For instance, you can do this:

dragRect.X := 100;
dragRect.width := 10;

but you can't do this:

dragRect.left := 100;
dragRect.right :=110;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文