function TMyShape.GetHeight: Integer;
begin
Result := inherited Height;
end;
function TMyShape.GetWidth: Integer;
begin
Result := inherited Width;
end;
procedure TMyShape.Paint;
var
X, Y, W, H, S, W1, H1, W2, H2: Integer;
begin
with Canvas do
begin
Pen := inherited Pen;
Brush := inherited Brush;
X := Pen.Width div 2;
Y := X;
W := Width - Pen.Width + 1;
H := Height - Pen.Width + 1;
W1 := FTopFrameWidth - Pen.Width + 1;
H1 := FTopFrameHeight - Pen.Width + 1;
W2 := FBottomFrameWidth - Pen.Width + 1;
H2 := FBottomFrameHeight - Pen.Width + 1;
if Pen.Width = 0 then
begin
Dec(W);
Dec(H);
Dec(W1);
Dec(H1);
Dec(W2);
Dec(H2);
end;
if W < H then S := W else S := H;
// 画两个矩形
Rectangle(X, Y, X + W1, Y + H1);
Rectangle(X, Y + H1, X + W2, Y + H1 + H2);
end;
end;
procedure TMyShape.SetBottomFrameHeight(const Value: Integer);
begin
if FBottomFrameHeight <> Value then
begin
FBottomFrameHeight := Value;
SetHeight(FTopFrameHeight + FBottomFrameHeight);
Invalidate;
end;
end;
procedure TMyShape.SetBottomFrameWidth(const Value: Integer);
begin
if FBottomFrameWidth <> Value then
begin
FBottomFrameWidth := Value;
if FBottomFrameWidth > FTopFrameWidth then
SetWidth(FBottomFrameWidth)
else
SetWidth(FTopFrameWidth);
Invalidate;
end;
end;
procedure TMyShape.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
if AWidth <> Width then
if FTopFrameWidth = FBottomFrameWidth then
begin
FTopFrameWidth := AWidth;
FBottomFrameWidth := AWidth;
end
else if FTopFrameWidth > FBottomFrameWidth then
begin
FBottomFrameWidth := AWidth * FBottomFrameWidth div FTopFrameWidth;
FTopFrameWidth := AWidth;
end
else begin
FTopFrameWidth := AWidth * FTopFrameWidth div FBottomFrameWidth;
FBottomFrameWidth := AWidth;
end;
if AHeight <> Height then
if FTopFrameHeight = FBottomFrameHeight then
begin
FTopFrameHeight := AHeight div 2;
FBottomFrameHeight := AHeight - FTopFrameHeight;
end
else begin
FTopFrameHeight := AHeight * FTopFrameHeight div (FTopFrameHeight + FBottomFrameHeight);
FBottomFrameHeight := AHeight - FTopFrameHeight;
end;
inherited;
Invalidate;
end;
procedure TMyShape.SetHeight(const Value: Integer);
begin
if GetHeight <> Value then
begin
inherited Height := Value;
end;
end;
procedure TMyShape.SetTopFrameHeight(const Value: Integer);
begin
if FTopFrameHeight <> Value then
begin
FTopFrameHeight := Value;
SetHeight(FTopFrameHeight + FBottomFrameHeight);
Invalidate;
end;
end;
procedure TMyShape.SetTopFrameWidth(const Value: Integer);
begin
if FTopFrameWidth <> Value then
begin
FTopFrameWidth := Value;
if FTopFrameWidth > FBottomFrameWidth then
SetWidth(FTopFrameWidth)
else
SetWidth(FBottomFrameWidth);
Invalidate;
end;
end;
procedure TMyShape.SetWidth(const Value: Integer);
begin
if GetWidth <> Value then
begin
inherited Width := Value;
end;
end;