|
; H := S;
end;
case FShape of
stRectangle, stSquare:
Rectangle(X, Y, X + W, Y + H);
stRoundRect, stRoundSquare:
RoundRect(X, Y, X + W, Y + H, S div 4, S div 4);
stCircle, stEllipse:
Ellipse(X, Y, X + W, Y + H);
//以下是增加的部分。
stHLine:
begin
MoveTo(X, Height div 2);
LineTo(X+W,Height div 2);
end;
stVLine:
begin
MoveTo(Width div 2,Y);
LineTo(Width div 2,Y+H);
end;
stTriangle:
Polygon([Point(X,Y+H-1),Point(X+W-1,Y+H-1),Point(Width div 2,Y)]);
stDiamond:
Polygon([Point(Width div 2,Y),Point(X,Height div 2),
Point(Width div 2,Y+H-1),Point(X+W-1, Height div 2)]);
end;
end;
end;
//Invalidate这个函数将使系统发送WM_PAINT给TGraphicControl
//TGraphicControl的处理函数将调用Paint,而它的子类覆盖了它
//所以实际就调用了ShapeEx的Paint函数,从而达到了重画的效果
procedure TShapeEx.StyleChanged(Sender: TObject);
begin
Invalidate;
end;
procedure TShapeEx.SetBrush(Value: TBrush);
begin
FBrush.Assign(Value);
end;
procedure TShapeEx.SetPen(Value: TPen);
begin
FPen.Assign(Value);
end;
//设置图形,同时引起重画,以达到图形变化,
//最明显的效果是在设计器时改变Shape属性时看到的变化
procedure TShapeEx.SetShape(Value: TShapeType);
begin
if FShape <> Value then
begin
FShape := Value;
Invalidate;
end;
end;
end.
安装等方法在上一章已经说过了,这里不多说。这一次知道了图形控件的大概做法,其实无非就是覆盖Paint来画自己的图形控件,而其他,则和我们上一章的说过的一样。其实也很简单。
以上两个控件算是比较简单,但已经讲清了很多组件制作的概念和技巧,看不看得懂就由你了,我也没有办法。有一个有用的技巧就是多看看VCL的源码,你会学到更多的东西。
接下来,应该要做一个难一点了吧。想知道是什么,且听下回分解。
上一页 [1] [2] [3] 没有相关教程
|