This article has been excerpted from book "Graphics Programming with GDI+".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 Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); //Create rectangles and regions Rectangle rect1 = new Rectangle(20, 20, 60, 80); Rectangle rect2 = new Rectangle(50, 30, 60, 80); Region rgn1 = new Region(rect1); Region rgn2 = new Region(rect2); //If region is not empty, empty it if (!rgn1.IsEmpty(g)) rgn1.MakeEmpty(); //If region is not infinite, make it infinite if (!rgn2.IsInfinite(g)) rgn2.MakeInfinite(); //Get bounds of the infinite region RectangleF rect = 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 regionConclusionHope 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.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: