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.