Delphi Screen Drawing

Source: Internet
Author: User

The following code centers the cursor and draws a cross on the full screen:

Procedure tform1.button1click (Sender: tobject );
VaR
Fullscreencanvas: TCanvas;
DC: HDC;
Begin
DC: = getdc (0); // obtain the DC of the screen. parameter 0 indicates the screen.
Fullscreencanvas: = TCanvas. Create; // create a canvas object
Fullscreencanvas. Handle: = Dc; // You can associate the canvas with a screen handle to make a picture.
Fullscreencanvas. moveTo (mouse. cursorpos. X, 0 );
Fullscreencanvas. lineto (mouse. cursorpos. X, 768 );
Fullscreencanvas. moveTo (0, mouse. cursorpos. y );
Fullscreencanvas. lineto (1024, mouse. cursorpos. y );
End;

 

 

 

The following code draws a cross in the center of the full screen:

Procedure tform1.button1click (Sender: tobject );
VaR
Fullscreencanvas: TCanvas;
DC: HDC;
Begin
DC: = getdc (0); // obtain the DC of the screen. parameter 0 indicates the screen.
Fullscreencanvas: = TCanvas. Create; // create a canvas object
Fullscreencanvas. Handle: = Dc; // You can associate the canvas with a screen handle to make a picture.
Fullscreencanvas. moveTo (screen. Width Div 2, 0 );
Fullscreencanvas. lineto (screen. Width Div 2,768 );
Fullscreencanvas. moveTo (0, screen. Height Div 2 );
Fullscreencanvas. lineto (1024, screen. Height Div 2 );
End;

// The following code periodically draws a cross, a square, and a circle in the middle of the screen

Procedure tform1.timer1timer (Sender: tobject );
VaR
Mycanvas: TCanvas;
DC: HDC;
Begin
DC: = getdc (0 );
Mycanvas: = TCanvas. Create;
// Mycanvas. Brush. Color: = clblack; // black fill color
Mycanvas. Brush. Style: = bsclear; // No background color
Mycanvas. Handle: = Dc;
// Mycanvas. Brush. Bitmap: = image1.picture. Bitmap;
Mycanvas. moveTo (screen. Width Div 2, 0 );
Mycanvas. lineto (screen. Width Div 2, screen. Height );
Mycanvas. moveTo (0, screen. Height Div 2 );
Mycanvas. lineto (screen. Width, screen. Height Div 2 );
Mycanvas. rectangle (screen. width Div 2-100, screen. height Div 2-100, screen. width Div 2 + 100, screen. height Div 2 + 100); // draw a square in the center of the screen
Mycanvas. ellipse (screen. width Div 2-100, screen. height Div 2-100, screen. width Div 2 + 100, screen. height Div 2 + 100); // draw a circle in the center of the screen
Mycanvas. textout (720,300, 'test again, test the feeling of writing directly on the screen! '); // Add text to the canvas object
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.