GDI+ GetBounds and Other Methods in VB.NET
In this article I will explain about the GetBounds and Other Methods of the Region class.
The IsEmpty method takes a Graphics object as an argument and returns true if a region is empty. Otherwise it returns false. IsInfinite returns true is a region is infinite (otherwise it returns false), and it takes a Graphics object as the only argument.
The MakeEmpty and MakeInfinite methods make a region empty or infinite, respectively. An infitinite region complete covers the area of a control.
The GetBound method returns the bounds of a region. The method also takes a Graphics object as an argument.
The code in Listing 6.10 uses the methods. It makes rgn2 infinite and fills it with a red pen, which fills the entire form with red.
LISTING 6.10: Using GetBounds and other methods of the Region class
'Create a Graphics object
Dim g As Graphics = Me.CreateGraphics()
g.Clear(Me.BackColor)
'Create rectangles and regions
Dim rect1 As New Rectangle(20, 20, 60, 80)
Dim rect2 As New Rectangle(50, 30, 60, 80)
Dim rgn1 As New Region(rect1)
Dim rgn2 As New Region(rect2)
'If region is not empty, empty it
If Not rgn1.IsEmpty(g) Then
rgn1.MakeEmpty()
End If
'If region is not infinite, make it infinite
If Not rgn2.IsInfinite(g) Then
rgn2.MakeInfinite()
End If
'Get bounds of the infinite region
Dim rect As RectangleF = rgn2.GetBounds(g)
'Display
MessageBox.Show(rect.ToString())
'Fill the region
g.FillRegion(Brushes.Red, rgn2)
'Dispose of object
g.Dispose()
An infinite region's starting coordinates are negative number, and its height and width are large positive numbers, as figure 6.10 shows. Using FillRegion on an infinite region fills the entire form.
FIGURE 6.10: Bounds of an infinite region
Conclusion
Hope the article would have helped you in understanding the GetBounds and Other Methods of the Region class in GDI+. Read other articles on GDI+ on the website.