Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report for Bug 7007 on
GitHub or Developer Community if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
If Graphics.SetClip is used in combination with changing the PageUnit and applying transformations, then the resulting clip area does not match the results in Windows .net 2 runtime. It appears that some of the transformation and/or unit change logic is applied to the clipping area, which is ignored within the Microsoft runtime. However the exact results are strange enough that I've been unable to deduce exactly what is occurring in order to devise a work-around.
To reproduce, create a blank Windows.Forms form at least 60mm * 60mm, and add this code to the form Paint event:
Rectangle rct = new Rectangle(5, 5, 50, 50);
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
e.Graphics.DrawRectangle(Pens.Red, rct); // draw expected target area
// try to set clipping area just inside drawn line...
e.Graphics.TranslateTransform(5, 5); // has no effect on clipped area in Windows
e.Graphics.Clear(Color.Green); // shows clipping area by colouring entire (clipped) graphics surface
// resulting rectangle should be just inside red rectangle
// or: e.Graphics.FillRectangle(Brushes.Green, 0, 0, 50, 50);
Results differ between Windows and Mac with Mono runtime, with the latter giving illogical/unpredictable results. The order of changing page unit, clipping and applying transformations appears to make little difference - results are incorrect no matter which order effects are applied. I believe the same issue occurs with other transformations, not just TranslateTransform.
If the PageUnit is left as pixel, the code above works correctly showing the clipped area inside the (now smaller) rectangle, matching the results on Windows.