How to draw cross on desktop
This Delphi graphic tutorial shows how to draw a cross on desktop on mouse click event, basic technique is use of full screen transparent form.
Bookmark:
How to draw cross on desktop
To create transparent background form set Brush Style to Clear mode. The Brush property accesses the TBrush object that determines pattern and color for the control background. Brush is a read-only property, but an application can manipulate the TBrush object by setting its properties or by using its Assign method. The Style property determines the pattern painted by the brush, unless a value is assigned to Bitmap.
Use Mouse object to get information about the system mouse, including which window (if any) has captured the mouse, the position of the mouse, and mouse settings from the control panel. Use CursorPos to get the position of the mouse cursor in global coordinates.
In order to create a full screen form, please do following changes to the form using Object inspector
Window state – Maximized
Border style – None
Use following commands to make transparent form and set line width and color at form create.
procedure TForm1.FormCreate(Sender: TObject); begin { Set transparent background } Brush.Style:=bsClear; { Set pen color and width } Canvas.Pen.Color:=clBlack; Canvas.Pen.Width:=10; end;
This one does the drawing of crosses at mouse position.
procedure TForm1.FormClick(Sender: TObject); Var X, Y : Integer; begin { Use CursorPos to get the position of the mouse cursor in global coordinates.} X:=Mouse.CursorPos.X; Y:=Mouse.CursorPos.Y; Canvas.MoveTo(0,Y); Canvas.LineTo(Form1.Width,Y); Canvas.MoveTo(X,0); Canvas.LineTo(X,Form1.Height); end;
Download This Delphi Tutorials.
Download materials for this article (Delphi - Tutorials)
draw-cross-on-desktop.zip
File size: 7 KB, File type: zip
Total downloads: 378, Upload date: February 11 - 2009