這是用Delphi柏林10.1更新2如何畫一條線在Delphi的FMX帆布
下工作(我得到的連線):
brush := TStrokeBrush.Create(TBrushKind.Solid, TAlphaColors.Lightgray);
brush.Thickness := 2;
with Canvas do
begin
BeginUpdate;
DrawLine(PointF(10, 10), PointF(100, 10), 1, brush);
EndUpdate;
end;
下不工作:
with Canvas do
begin
BeginUpdate;
Stroke.Color := TAlphaColors.Black;
Stroke.Thickness := 2.0;
DrawLine(PointF(10, 10), PointF(100, 10), 1);
EndUpdate;
end;
爲什麼我不能使用第二個?我怎樣才能使它工作,還是應該堅持像第一個例子那樣創建一個筆觸?
我已經包含了最小的應用程序:
main.pas
unit main;
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
TMainForm = class(TForm)
PaintBox: TPaintBox;
procedure OnPaint(Sender: TObject; Canvas: TCanvas);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.fmx}
procedure TMainForm.OnPaint(Sender: TObject; Canvas: TCanvas);
begin
with Canvas do
begin
BeginUpdate;
Stroke.Color := TAlphaColors.Black;
Stroke.Thickness := 2.0;
DrawLine(PointF(10, 10), PointF(100, 10), 1);
EndUpdate;
end;
end;
end.
main.fmx:
object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 480
ClientWidth = 640
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object PaintBox: TPaintBox
Position.X = 16.000000000000000000
Position.Y = 16.000000000000000000
Size.Width = 609.000000000000000000
Size.Height = 449.000000000000000000
Size.PlatformDefault = False
OnPaint = OnPaint
end
end
test.dpr:
program test;
uses
System.StartUpCopy,
FMX.Forms,
main in 'main.pas' {MainForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
你的第二個例子中的代碼是好的。請顯示[mcve]。你可能試圖在'Paint'方法或'OnPaint'處理程序之外繪製? –
'Stroke.Kind:= TBrushKind.bkSolid;'可能在Android上需要,因爲它默認是'bkNone'。在Windows上,默認值是'bkSolid'。 –
我已經添加了顯示問題所需的最小文件 – imekon