(WPF and C#) Using a For Loop to draw multiple Rectangles

jefe323

Distinguished
Feb 14, 2010
89
0
18,590
2
I'm working on a project for school and I'm kind of stumped. I have a grid (10 columns and 5 rows) and I want to fill each cell with a rectangle.

The user will be able to specify how many cells are filled at runtime...

Here is the code I have written to draw a single rectangle in a specified cell ( (2,2) for testing purposes ):

[cpp]
public void CreateTempRectange()
{
Rectangle temp = new Rectangle();
temp.Height = ( (mainWindow.Height/5) - 10 );
temp.Width = ( (mainWindow.Width/10) - 5 );

temp.StrokeThickness = 1;
temp.Stroke = blackBrush;

temp.SetValue(Grid.RowProperty, 2);
temp.SetValue(Grid.ColumnProperty, 2);

myGrid.Children.Add(temp);
}
[/cpp]

Is there a way I can create a for loop to create a rectangle in each cell?
 
Thread starter Similar threads Forum Replies Date
Katsugeo Apps General Discussion 1
B Apps General Discussion 2
D Apps General Discussion 1
P Apps General Discussion 2
S Apps General Discussion 4
john vitz Apps General Discussion 5
P Apps General Discussion 2
A Apps General Discussion 1
bokrael Apps General Discussion 1
C Apps General Discussion 1
M Apps General Discussion 8
IrishLaad Apps General Discussion 1
S Apps General Discussion 1
SyncroScales Apps General Discussion 1
P Apps General Discussion 1
C Apps General Discussion 2
R Apps General Discussion 1
M Apps General Discussion 2
yrralrellim Apps General Discussion 9
A Apps General Discussion 1

ASK THE COMMUNITY

TRENDING THREADS