【发布时间】:2014-02-10 23:55:25
【问题描述】:
我尝试使用 TShape 在 TEdit 字段周围绘制彩色边框。我定义了以下组件:
type TGEdit = class(TEdit)
private
m_shape : TShape;
protected
procedure setBorderColor( brd_col : TColor );
procedure setBorderWidth( brd_wid : integer );
public
constructor create(AOwner : TComponent); override;
destructor destroy(); override;
published
property borderColor : TColor read m_border_color write setBorderColor default clBlack;
property borderWidth : integer read m_border_width write setBorderWidth default 1;
end;
在构造函数中定义一个 TShape 对象。
constructor TGEdit.create(AOwner : TComponent);
begin
inherited;
Self.BorderStyle:= bsNone;
m_border_color := clBlack;
m_border_width := 1;
m_shape := TShape.Create(AOwner);
m_shape.Parent := Self.Parent;
m_shape.Shape := stRectangle;
m_shape.Width := Self.Width+2*m_border_width;
m_shape.Height := Self.Height+2*m_border_width;
m_shape.Left := Self.Left-m_border_width;
m_shape.Top := self.Top-m_border_width;
m_shape.Brush.Style := bsClear;
m_shape.Pen.Color := m_border_color;
m_shape.Pen.Style := psSolid;
end;
destructor TGNumberEdit.destroy();
begin
m_shape.Free();
inherited;
end;
定义一个改变边框颜色和宽度的程序
procedure TGEdit.setBorderColor( brd_col : TColor );
begin
if m_border_color = brd_col then
exit;
m_border_color := brd_col;
m_shape.Pen.Color := m_border_color;
end;
procedure TGEdit.setBorderWidth( brd_wid : integer );
begin
if (m_border_width = brd_wid) or (brd_wid < 0) then
exit;
m_border_width := brd_wid;
m_shape.Pen.Width := m_border_width;
end;
但是当我将组件放在表单上时,不会绘制形状。我的代码哪里出错了?
【问题讨论】:
标签: delphi