19th Chapter-delphi Custom Parts Development (IV.) (1)

Source: Internet
Author: User

19.3.2 Create a graphic part

Graphic control is a kind of simple component. Because a pure graphic part does not need keyboard focus, it does not have a window handle. Application users with graphics control can still control with the mouse, but there is no keyboard interface.

The graphical part provided in this example is Tshape. The shape part is located on the additional page of the component palette. The shape part in this example is different, so it is called Tsampleshape.

Creating a graphics part requires the following three steps:

Create and register a part

Advertisement (Publishing) inherited properties

Add Graphics Features

19.3.2.1 Create and register parts

The creation of each part starts in the same way, in this case, as follows:

Set up a part unit called shapes

Inherit from Tgraphiccontrol, call the new part Tsampleshape

Register on the Component Palette's Samples page Tsampleshape

Unit Shapes

Intertace

Use Sysutils, Wintypes, Winprocs, Messages, Classes,

graphics,controls,forms;

Type

Tsampleshape=class (Tgraphiccontrol)

End

Implementation

Procedure Register;

Begin

Registercomponents (' Samples ', [Tsampleshape]);

End

End.

19.3.2.2 To advertise inherited properties

Once you decide on a part type, you can decide which properties and events are visible to the user in the protected part of the parent class. Tgraphiccontrol has published all properties that are controlled as graphics, so just advertise the properties that respond to mouse and drag-and-drop events.

Type

Tsampleshape=class (Tgraphiccontrol)

Published

Property dragcursor;

Property dragmode;

Property ondragdrop;

Property ondragover;

Property Onenddrag;

Property OnMouseDown;

Property OnMouseMove;

Property OnMouseup;

End

In this way, the shape controls the ability to interact with the user through the mouse and drag-and-drop.

19.3.2.3. Increase graphics capability

Once you have declared the graphic part and advertised the inherited properties, you can add graphics functionality to the part. Now you need to know two points:

Decide what to draw

How to draw part graphics

In the case of shape control, you need to add some properties that enable the user to change the shape at design time.

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.