Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FillRectangles Method 1

Status
Not open for further replies.

monksnake

Programmer
Oct 14, 2005
2,145
US
Is there a way to use the FillRectangles method on an array of rectangles and be able to specify a different color for each rectangle if I choose?

Or do I have to draw each rectangle separate and fill them that way???

[monkey][snake] <.
 
If you have a [tt]List<Rectangles>[/tt] you can use the ForEach(Action) function to preform calculations against each rectangle.
here's the msdn link []

If you want to do comparisons, or other logic with within the Action delegate, you'll need to delcare variables and assign them before calling the delegate.

here's an example
Code:
public class Test
{
   public List<int> numbers = new List<int>(new int[] { 1, 2, 3, 4 } );
   private int modulo = 2;

   private void IsEven(int n)
   {
      Console.WriteLine("{0} mod {1} is {2}", n, this.module, n % this.modulo);
   }

   public void PrintModuloToConsole()
   {
      this.numbers.ForEach(IsEven);
   }
}


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I just figured out what I needed.

Thanks for the info though jmeckley, here have a *.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top