You are on page 1of 1
int nunRoxs ~ PascaleTriangle.count; for (int rowNum = 1; rowNum <= nunRows; roxNunt+) 4 /{ Start on the left so the row is centered. Ant x = ox ~ rownum * wid / 27 // vraw the items in this row. List row = PascalsTriangie{rowNum - 1]; for (int colum = 1; colNum <= rowwun colNumt+) 4 Rectangle rect = new Rectangle x + margin, y + margin, wid = 2* margin, bgt ~ 2 * margin); gr-DrawString (row [colNum - 1].Tostring(), font, Brushes.Blue, rect, sf); gr-DrawGilipse (Pena.Black, rect); , ‘The PascalsTriangle variable holds the solution found by the previous MakePascalsTriangle method, The Drawrriangle method first performs some setup chores. It makes a StringFormat object that it can use to center text in a rectangle and creates a font. It then initializes the variable y to indicate the vertical position of the first row. ‘The method then loops through the triangle’s rows. For each row, the method calculates the row's width, divides that by 2, and subtracts the result from the X coordinate of the center of the PictureBox. That gives the X coordinate where the program must start drawing the row in order to center it horizontally. Next, the code loops through the row to draw its values, updating the variable x after each. To draw a value, the code makes a rectangle at position (x,y), and with the width and height given by the constants wid and hat. It offsets the position and dimensions to make a margin between values. This method draws the value centered inside the rectangle and then uses the same rectangle to draw an ellipse around the value

You might also like