Intersect method of a Region means to update the region data with its intersection with another Region, GraphicsPath, Rectangle, or RectangleF. If the second object is totally inside the region then its intersect bounds shoud be exactly the same as the object itself (at least thats what I think). But this is not true with ellipses and regions, as the Y of the intersect region is 1 more than the Y of the ellipse and its height is one less, but X and Width are the same. That does not happen for Rectanlges. Try the following codes to see what I mean.
Returns FalseVB Code:
Dim gPath As New Drawing.Drawing2D.GraphicsPath gPath.AddEllipse(New RectangleF(3, 3, 10, 10)) Dim rg As New Region(New RectangleF(0, 0, 20, 20)) rg.Intersect(gPath) MessageBox.Show(rg.GetBounds(Me.CreateGraphics).Equals(gPath.GetBounds))
Returns TrueVB Code:
Dim gPath As New Drawing.Drawing2D.GraphicsPath gPath.AddRectangle(New RectangleF(3, 3, 10, 10)) Dim rg As New Region(New RectangleF(0, 0, 20, 20)) rg.Intersect(gPath) MessageBox.Show(rg.GetBounds(Me.CreateGraphics).Equals(gPath.GetBounds))
Returns TrueVB Code:
Dim gPath As New Drawing.Drawing2D.GraphicsPath gPath.AddEllipse(New RectangleF(3, 3, 10, 10)) Dim rec As New RectangleF(0, 0, 20, 20) MessageBox.Show(RectangleF.Intersect(rec, gPath.GetBounds).Equals(gPath.GetBounds))
Returns TrueVB Code:
Dim gPath As New Drawing.Drawing2D.GraphicsPath gPath.AddRectangle(New RectangleF(3, 3, 10, 10)) Dim rec As New RectangleF(0, 0, 20, 20) MessageBox.Show(RectangleF.Intersect(rec, gPath.GetBounds).Equals(gPath.GetBounds))




Reply With Quote