Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
C# Programming

Drawing and filling rectangles. Using colour.

 

Graphics

Drawing and filling rectangles. Using colour.

1. [ C# ] Drawing rectangles and using colour


Big

draw
The word draw is often used to indicate that only the outline shows
pen and stroke are associated with drawing
fill
Typically fill is used to indicate that the shape is filled in a solid way
brush and fill are associated with filling

The Graphics method allows us to draw or to fill rectangles.

DrawRectangle(Pens.Blue,10,10,70,50)
Draws the rectangle using the blue pen.
FillRectangle(Brushes.Red,200,0,100,400)
Fills the rectangle. The top left corner of the rectangle is at 200,0 the width and height are 100 and 400.
FillRectangle(new SolidBrush( Color.FromArgb(255,128,128)), 10,70,150,50)
This fill a rectangle with an awful pink. The three numbers are the Red, Green and Blue components. The maximum value for each component is 255 - so 255,128,128 means full red, half green and half blue.

We produce three rectangles. One uses drawRect, the others use fillRect.

three rectangles