Line Drawing Demonstration


The program of this section demonstrates drawing of various types of figures supported by the graphics engine. The output of the program is shown below.

The program draws:

It should be apparent from the output that certain of the primitives fill the area enclosed within. The portion of the program that draws the figures is shown below.

void OnPaint(object source, PaintEventArgs e)
{
    DeviceContext deviceContext = new DeviceContext(this);
    deviceContext.Brush = redBrush;
    deviceContext.DrawRectangle(W / 8, H / 8, 7 * W / 8, 7 * H / 8);
    deviceContext.CurrentPosition = new Point(0,0);
    deviceContext.DrawLineTo(W,H);
    deviceContext.CurrentPosition = new Point(0,H);
    deviceContext.DrawLineTo(W,0);
    deviceContext.Brush = greenBrush;
    deviceContext.DrawEllipse(W / 8, H / 8, 7 * W / 8, 7 * H / 8);
    deviceContext.Brush = blueBrush;
    deviceContext.DrawRoundedRectangle(W / 4, H / 4, 3 * W / 4, 3 * H / 4, W / 4, H / 4);
}

Drawn first is a rectangle from 1/8 to 7/8 the size of the client window (in both directions). Next, two lines that form the diagonals of the client are drawn. An ellipse with the given coordinates is overlaid, covering from 1/8 to 7/8 of the client (in both the vertical and horizontal directions). Finally, an elliptically rounded rectangle of the given dimensions is drawn. It should be apparent from the structure of the display that certain of the primitives are overlaid (hence their interiors are drawn).