在运行时可视化线上的渐变

时间:2018-11-01 20:18:57

标签: delphi firemonkey

我正在尝试在运行时创建Tline形状并分配渐变,但没有成功。创建其他形状(例如圆形或正方形)时,不会出现问题。

注意:在设计时,Tline形状会进行渐变。我正在使用东京10.2版

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate (Sender: TObject);
var
  DLine     : TLine;
begin
  DLine := Tline.Create (nil);
  DLine.Position.x := 100;
  DLine.Position.y := 100;
  DLine.Height := 300;
  DLine.LineType := TLineType.Left;
  DLine.Stroke.Thickness := 3;
  DLine.Fill.Gradient.Color :=   $FF0000FF; // Blue
  DLine.Fill.Gradient.Color1 :=  $FFFF7F50; // Coral
  DLine.Fill.Kind := TBrushKind.Gradient;
  DLine.Fill.Gradient.Style := TGradientStyle.Linear;
  DLine.Parent := Form1;
end;

end.

1 个答案:

答案 0 :(得分:2)

enter image description here 使用DLine.Stroke而不是DLine.Fill

int i = 0;

protected void Timer1_Tick(object sender, EventArgs e)
{
    //check if the viewstate with the value exists
    if (ViewState["timerValue"] != null)
    {
        //cast the viewstate back to an int
        i = (int)ViewState["timerValue"];
    }

    i++;

    Label3.Text = i.ToString();

    //store the value in the viewstate
    ViewState["timerValue"] = i;
}