• Delphi XE2 之 FireMonkey 入门(6) TLine、TEllipse、TCircle、TPie、TArc、TRectangle、TRoundRect、TCalloutRectangle



    它们都是继承自 TShape 类, 共同拥有如下属性:
    Fill            : TBrush;      //填充
    Stroke          : TBrush;      //边线(画笔)
    StrokeThickness : Single;      //厚度(边线宽度)
    StrokeCap       : TStrokeCap;  //线帽样式, TStrokeCap (枚举)类型
    StrokeDash      : TStrokeDash; //虚线样式, TStrokeDash(枚举)类型
    StrokeJoin      : TStrokeJoin; //拐点结合样式, TStrokeJoin(枚举)类型
    ShapeRect       : TRectF;      //可填充范围的矩形(相对于当前图形)
    


    TLine 用不着 Fill, 但增加了 LineType 属性(TLineType 枚举类型);

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Line1.LineType := TLineType.ltDiagonal; //斜线
      Line2.LineType := TLineType.ltTop;      //横线
      Line3.LineType := TLineType.ltLeft;     //竖线
    end;
    


    TElipse 和 TCircle 没有新属性, 应该也用不着 StrokeCap、StrokeJoin.
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Ellipse1.StrokeDash := TStrokeDash.sdDot; //虚线样式
      Circle1.Fill.Kind := TBrushKind.bkNone;   //取消填充
    end;
    


    TArc 和 TPie 增加了 StartAngle、EndAngle 属性.



    TRectangle 增加了控制圆角的 XRadius、YRadius 属性、控制边线的 Sides 属性、控制四个角的 Corners、CornerType 属性;

    TRoundRect 只加了 Corners 属性; 看来要做更随意的圆角矩形得用 TRectangle 而不是 TRoundRect.
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Rectangle1.Position.X := 50;
      Rectangle1.Position.Y := 10;
      Rectangle1.Width := 100;
      Rectangle1.Height := 120;
      Rectangle1.StrokeThickness := 16;
      Rectangle1.Fill.Color := $80FF0000;
      Rectangle1.Stroke.Color := $800000FF;
    
      Rectangle1.XRadius := 8;
      Rectangle1.YRadius := 8;
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      Rectangle2.Position.X := 350;
      Rectangle2.Position.Y := 10;
      Rectangle2.Width := 100;
      Rectangle2.Height := 120;
      Rectangle2.StrokeThickness := 4;
      Rectangle2.Fill.Color := claRed;
      Rectangle2.Stroke.Color := claBlack;
    
      Rectangle2.CornerType := TCornerType.ctBevel;
      Rectangle2.Corners := [TCorner.crBottomLeft, TCorner.crBottomRight];
      Rectangle2.Sides := [TSide.sdBottom, TSide.sdRight];
    
      //关于 Corners 和 Sides 还有两个非常方便的常量: AllCorners、AllSides
    end;
    


    TCalloutRectangle 很有意思, 矩形外带一个三角, 应该是用于图形化的注释.

    给它增加的 CalloutWidth、CalloutLength、CalloutPosition、CalloutOffset 四个属性都是用于控制三角的.
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      CalloutRectangle1.Width := 200;
      CalloutRectangle1.Height := 150;
      CalloutRectangle1.CalloutPosition := TCalloutPosition.cpBottom;
      CalloutRectangle1.CalloutWidth := CalloutRectangle1.Width / 4;
      CalloutRectangle1.CalloutLength := CalloutRectangle1.Height / 2;
      CalloutRectangle1.CalloutOffset := -CalloutRectangle1.Width / 2;
    end;
    


    这其中需要进一步学习的是 Fill、Stroke 属性, 它们都是 TBrush 类型, 会涉及到 TBitmap、TBitmapObject、TCanvas 等等.
  • 相关阅读:
    洛谷P1880 石子合并
    洛谷P3265 装备购买
    bzoj1345 序列问题
    从群里抄来的某题
    poj2689 Prime Distance
    灯 & 树
    [HNOI2013]游走
    A
    B
    hdu 1247 Hat’s Words(字典树)
  • 原文地址:https://www.cnblogs.com/del/p/2185086.html
Copyright © 2020-2023  润新知