These procedures draw two diagonal straight lines on an image in a VCL form.
- Create a VCL form.
- Code the form's OnPaint event handler to draw the straight lines.
- Build and run the application.
To create a VCL form and place an image on it
- Choose FileNewOtherDelphi for .NET ProjectsVCL Forms Application.
- Click the Design tab, if necessary, to display Form1 properties in the Object Inspector.
To write the OnPaint event handler
- In the Object Inspector, click the Events tab.
- In the Visual category, double-click the OnPaint event. The Code Editor displays with the cursor in the TForm1.FormPaint event handler block.
- 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
- Save all files in your project.
- 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.