コード例 #1
0
        public static Rectangle GetBoundsInt(this Region region)
        {
            Rectangle[] scans = new Rectangle[0];
            using (NullGraphics nullGraphics = new NullGraphics())
            {
                IntPtr hRgn = IntPtr.Zero;

                try
                {
                    hRgn = region.GetHrgn(nullGraphics.Graphics);
                    GetRegionScans(hRgn, out scans);
                }

                finally
                {
                    if (hRgn != IntPtr.Zero)
                    {
                        SafeNativeMethods.DeleteObject(hRgn);
                        hRgn = IntPtr.Zero;
                    }
                }
            }

            if (scans.Length == 0)
            {
                return(Rectangle.Empty);
            }

            Rectangle bounds = scans[0];

            for (int i = 1; i < scans.Length; i++)
            {
                bounds = Rectangle.Union(bounds, scans[i]);
            }

            return(bounds);
        }
コード例 #2
0
        public static Rectangle[] GetRegionScansReadOnlyInt(this Region region)
        {
            Rectangle[] scans = new Rectangle[0];
            using (NullGraphics nullGraphics = new NullGraphics())
            {
                IntPtr hRgn = IntPtr.Zero;

                try
                {
                    hRgn = region.GetHrgn(nullGraphics.Graphics);
                    GetRegionScans(hRgn, out scans);
                }
                finally
                {
                    if (hRgn != IntPtr.Zero)
                    {
                        SafeNativeMethods.DeleteObject(hRgn);
                        hRgn = IntPtr.Zero;
                    }
                }
            }

            return(scans);
        }