The basic method (1) controls written in Delphi [Author: Ray Small Park Add Time: 2001-5-5 18:01:08]
Source: www.ccidnet.com
As a Delphi programmer, it is necessary to further improve the programming level, you must master the preparation method of the control. This article will introduce some basic methods and patterns of the preparation of the preparation of the initiator through a simple example.
This example control is called TLEiLabel, which is to add two practical functions on the basis of TLabel: First, make the text with a stereo shape, and the other is to make the text have hyperlink attributes. Let's take a step by step to implement these features.
First, make the text have stereo shapes
First define type T3deffect and attribute Style3D as follows:
T3Deffect = (Normal, raised, lowered, shadowed);
Property Style3D: T3deffect Read FStyle3d Write SetStyle3d Default Normal
The variable is defined in private: "FStyle3D: T3deffect;" and sets the setStyle3D () method as follows, which is also a general format of writing methods:
Procedure Tleilabel.setStyle3D (Value: T3deffect);
Begin
IF fStyle3D <> Value Then
Begin
FStyle3d: = Value;
Invalidate; // means the control will be redrawn
END;
END;
In addition to the text of the shadow, the shadow is also defined Shadexoffset and ShadeyOffset:
Property ShadowxOffset: Integer Read FXOffset Write SetFxOffset Default 5;
Property Shadowyoffset: Integer Read Fyoffset Write SetFyoffset Default -5;
Write the method setFxOffset (), setFyOffset (), and SETSTYLE3D () above.
To redraw control, you generally have to overload the Paint method. Here is just heavy graphics, we only need to overload the DodrawText method.
DodrawText's statement is placed in protected:
Procedure DodrawText (Var Rect: Treat; Flags: longint); OVERRIDE;
Here DodrawText () draws different texts according to four types (normal, projections, recesses and shadows).
Second, make the text have hyperlink attributes
Define an attribute URL indicates the URL or Email address to be linked.
Property URL: String Read Furl Write SetURL;
Write the method seturl as follows:
Procedure tleilabel.seturl (value: string);
Begin
IF furl <> value kilure: = value;
IF furl <> '' THEN
Cursor: = crhandpoint;
END;
When you click this Label to open a browser or send and receive a mail tool, you have to overload the Click method.
Procedure Click; Override;
Procedure tleilabel.click;