ARTICLE

GetBounds and Other Methods of the Region class in GDI+

Posted by Dinesh Beniwal Articles | ADO.NET in VB.NET May 19, 2010
In this article I will explain about the GetBounds and Other Methods of the Region class
 
Reader Level:

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.gif

FIGURE 6.10: Bounds of an infinite region

Conclusion

Hope the article would have helped you in understanding t
he
GetBounds and Other Methods of the Region class in GDI+. Read other articles on GDI+ on the website.

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor