这是Delphi Berlin 10.1 Update 2
以下作品(我画了一条线):
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.
答案 0 :(得分:5)
早期版本的Delphi具有Stroke.Kind的不同默认值,具体取决于平台。
自Delphi 10.1 Berlin以来,所有平台的默认值似乎都是None
。 (谢谢@TomBrunberg)
要显示该行,请设置Stroke.Kind := TBrushKind.Solid;
注意:在Windows 8.1上测试
我也创建了一个新的Metropolis FMX应用程序,其中绘图无需设置Stroke.Kind
即可。但不能解释这一点。
在QP,RSP-16313 The Canvas.DrawLine doesn't work at Windows XP (32 bit) forms提交了类似的报告。这里的问题出现在Windows-XP上,但不出现在Windows-7上。
答案 1 :(得分:0)
你应该使用笔画。
您应该使用BeginScene和EndScene而不是BeginUpdate和EndUpdate。这个片段非常完美:
Brush := TStrokeBrush.Create(TBrushKind.Solid, TAlphaColors.Black);
Brush.Thickness := 2;
with Canvas do
begin
BeginScene();
DrawLine(PointF(10, 10), PointF(100, 10), 1, Brush);
EndScene;
end;