/// <devdoc> /// Creates a WindowsRegion from a System.Drawing.Region. /// </devdoc> public static WindowsRegion FromRegion(Region region, Graphics g) { if (region.IsInfinite(g)) { // An infinite region would cover the entire device region which is the same as // not having a clipping region. Observe that this is not the same as having an // empty region, which when clipping to it has the effect of excluding the entire // device region. // To remove the clip region from a dc the SelectClipRgn() function needs to be // called with a null region ptr - that's why we use the empty constructor here. // GDI+ will return IntPtr.Zero for Region.GetHrgn(Graphics) when the region is // Infinite. return(new WindowsRegion()); } return(WindowsRegion.FromHregion(region.GetHrgn(g), true)); }