GDI +地区平等平等、地区、GDI

2023-09-06 11:29:44 作者:软萌嘤嘤嘤

为什么在以下code断言失败?为什么没有区域 A B 相等?

 地区=新区域(新的RectangleF(0.0,0.0,10.0f,10.0f));
  区域b =新区域();
  b.MakeEmpty();
  b.Union(新的RectangleF(0.0,0.0,10.0f,10.0f));
  Debug.Assert的(A == B区不等于);
 

解决方案

这是我所看到的, System.Drawing.Region 不覆盖对象的实施中的equals()。因此,你的 == 呼叫使用的ReferenceEquals 键,只是告诉你 A B 不在同一个对象。

请尝试使用 System.Drawing.Region.Equals(区,图形) 超载​​而是传递一个图形目标的背景下,你希望比较这两个地区。

VCL界面组件DevExpress VCL v21.2 支持Windows 11

Why does the assertion fail in the following code? Why aren't regions a and b equal?

  Region a = new Region(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f));
  Region b = new Region();
  b.MakeEmpty();
  b.Union(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f));
  Debug.Assert(a == b, "Regions not equal");

解决方案

From what I can see, System.Drawing.Region does not override Object's implementation of Equals(). Therefore your == call is using ReferenceEquals and simply telling you a and b are not the same object.

Try using the System.Drawing.Region.Equals(Region, Graphics) overload instead, passing in a Graphics object in the context you wish to compare the two regions.