Outside of viewbox - Printable Version
+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: ZoomPanel (https://forum.ab4d.com/forumdisplay.php?fid=8)
+--- Thread: Outside of viewbox (/showthread.php?tid=3964)
Outside of viewbox - Björn - 02-17-2016
Is there a ways to know if a control is in or out of the current viewbox?
I made a test with a grid (inside the zoom panel) that contains 100 x 100 rectangles. I want to change the colors of the rectangles which are inside or outside of the viewbox. In my example the ViewBox.Contains(Point) method never returns true.
public void UpdateViewbox(Ab2d.Controls.ZoomPanel panel)
foreach (Rectangle item in MyGrid.Children)
Point point = item.TranslatePoint(new Point(0,0), this);
item.Fill = Brushes.Red;
item.Fill = Brushes.Blue;
Is there an example of how to do that?
RE: Outside of viewbox - abenedik - 02-17-2016
The idea to use TranslatePoint and Contains methods is very interesting.
But the problem is that the ZoomPanel's Viewbox property is in relative units (1 is full width / height), but the translated points are in absolute positions.
The solution is pretty simple - instead of ZoomPanel's Viewbox you need to use a rectangle that is created from ZoomPanel's actual size:
RE: Outside of viewbox - Björn - 02-22-2016
Thank you for the corrected example, it works perfectly!