Cannot go back to old clip region

R

Reiner Obrecht

I save my old cliping region and do some work with a new clipping region.
When I want to switch back I get another clipping region contents in my
Graphics object than before. The saved region in "oldClip" is still correct.

Region oldClip = g.Clip;
g.Clip = new Region(path); // new region is perfect

// several drawings which are correct ....

g.Clip = oldClip; // it happens here

Has anyone an idea, where the problem can come from? Thanks for helping.
 
J

Jeff Johnson

I save my old cliping region and do some work with a new clipping region.
When I want to switch back I get another clipping region contents in my
Graphics object than before. The saved region in "oldClip" is still
correct.

How do you know the saved region is "still correct"?
Region oldClip = g.Clip;
g.Clip = new Region(path); // new region is perfect

// several drawings which are correct ....

g.Clip = oldClip; // it happens here

Has anyone an idea, where the problem can come from? Thanks for helping.

Not really. Everything looks good at first glance, but then I use the
SetClip() method and not the Clip property when dealing with clipping
regions, so I can't say I have any experience with cases like yours. (Not to
mention that I haven't yet had a need to save an existing clipping region.)

How about cloning? Make the first line

Region oldClip = (Region)g.Clip.Clone();
 
H

Herfried K. Wagner [MVP]

Jeff Johnson said:
Not really. Everything looks good at first glance, but then I use the
SetClip() method and not the Clip property when dealing with clipping
regions, so I can't say I have any experience with cases like yours. (Not
to mention that I haven't yet had a need to save an existing clipping
region.)

Setting the 'Clip' property will cause the following call: 'Me.SetClip(<new
value>, CombineMode.Replace)'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top