# [.net] [GDI+] Translating a Region

## Recommended Posts

In the following code:
Point[] vertices = { Point(50, 100), new Point(100, 50), new Point(150, 100) };
GraphicsPath path = new GraphicsPath();
region = new Region(path);
Graphics g = CreateGraphics();

region.Translate(10, 0);
int x1 = (int)region.GetBounds(g).X;
//region = region.Clone();
region.Translate(20, 0);
int x2 = (int)region.GetBounds(g).X;


x1 is 60, and I would expect x2 to be 80. However, it's only 80 if I uncomment the call to Clone(). Otherwise it's 60, as if the second call to Translate() has no effect. EDIT: If I comment out the line that assigns x1, then x2 is 80 whether I call Clone() or not. It's as if calling GetBounds() somehow "fixes" the bounds so that you can't modify them anymore? Any idea what's causing this? Thanks in advance. [Edited by - Gage64 on May 3, 2010 1:26:38 PM]

##### Share on other sites

Try adding a GetHRGN call followed by a GetRgnBox call. With that you can get the GDI region's equivalent RECT and you may see (as I did) that RECT.left is 61 for your first call and RECT.left is 81 for the second call.

But the docs say that "The rectangle returned by Region::GetBounds is not always the smallest possible rectangle."

So technically, all it has to do is return any rect that contains the region in order to be considered functioning properly. :)

##### Share on other sites
Thanks, I'll give it a try.

But I still don't understand why the first call to GetBounds() affects the second call, and why cloning the region changes this behavior.

##### Share on other sites
I did a bit more investigating. It's Translate that's buggy, not GetBounds. If you use a Matrix with Region's Transform, it works as expected.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628367
• Total Posts
2982279

• 10
• 9
• 13
• 24
• 11