RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Drawing Straight Lines In a VCL Forms Application

These procedures draw two diagonal straight lines on an image in a VCL form.

  1. Create a VCL form.
  2. Code the form's OnPaint event handler to draw the straight lines.
  3. Build and run the application.

To create a VCL form and place an image on it

  1. Choose FileNewOtherDelphi for .NET ProjectsVCL Forms Application.
  2. Click the Design tab, if necessary, to display Form1 properties in the Object Inspector.

To write the OnPaint event handler

  1. In the Object Inspector, click the Events tab.
  2. In the Visual category, double-click the OnPaint event. The Code Editor displays with the cursor in the TForm1.FormPaint event handler block.
  3. Enter the following event handling code:

with Canvas do
        begin
                MoveTo(0,0);
                LineTo(ClientWidth, ClientHeight);
                MoveTo(0, ClientHeight);
                LineTo(ClientWidth, 0);
        end;
To run the program

  1. Save all files in your project.
  2. Choose RunRun. The application executes, displaying a form with two diagonal crossing lines.
    Tip: To change the color of the pen to green, insert this statement following the first MoveTo() statement in the event handler code: Pen.Color := clRed; Experiment using other canvas and pen object properties.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!