创建数字键盘 Firemonkey Delphi 和带字体的动态创建按钮不起作用
Create Numeric Keyboard Firemonkey Delphi and Dynamic create button with Font are not working
我正在做一个触摸系统(Windows),它需要数字键盘来插入用户、手动输入、密码、退出系统。我更喜欢创建按钮,但属性字体不起作用。
我创建了一个 class:
unit uKeyboard;
interface
uses
FMX.Edit, FMX.StdCtrls, FMX.Layouts, SysUtils;
type
TKeyboard = class(TObject)
btnk : array [0..9] of TButton;
btnx : TButton;
btnbs : TButton;
edtk : TEdit;
procedure OnClickB (Sender : TObject);
procedure OnClickX (Sender : TObject );
procedure OnClickBS (Sender : TObject );
public
constructor Create (var GLayout1 : TGridLayout; var EdtText : TEdit);
destructor Destroy; override;
end;
implementation
constructor TKeyboard.Create(var GLayout1: TGridLayout; var EdtText: TEdit);
var
i : Integer;
begin
edtk := EdtText;
GLayout1.ItemWidth := Round(GLayout1.Width/3);
GLayout1.ItemHeight := Round(GLayout1.Height/4);
for i := 9 downto 0 do
begin
btnk[i] := TButton.Create(GLayout1);
with btnk[i] do
begin
Parent := GLayout1;
TextSettings.Font.Size := 40;
Text := IntToStr(i);
OnClick := OnClickB;
end;
end;
...
主单元内部:
uses
uKeyboard, ...;
var
Keyboard : TKeyboard;
// OnClickButton
Keyboard := TKeyboard.Create(GridLayout4,EdtRelease);
字体不是40:
根据文档:
Setting Text Parameters in FireMonkey: Using the StyledSettings Property
When changing text representation properties of the TTextSettings type objects, remember that when you are changing the value of a property (of the TextSettings.Font.Size
property in the previous example), then the actual changing of the object's view happens only if the ITextSettings.StyledSettings property does not contain the TStyledSetting.Size constant. The "Relation between TStyledSetting constants and TTextSettings properties" table shows which TStyledSetting constants control handling of the TTextSettings text representation properties.
因此,为了给 TButton.TextSettings.Font.Size
设置一个值,您需要从 TButton.StyledSettings
属性 中删除 TStyledSetting.Size
标志,例如:
btnk[i] := TButton.Create(GLayout1);
with btnk[i] do
begin
Parent := GLayout1;
StyledSettings := StyledSettings - [TStyledSetting.Size]; // <-- add this
TextSettings.Font.Size := 40;
Text := IntToStr(i);
OnClick := OnClickB;
end;
我正在做一个触摸系统(Windows),它需要数字键盘来插入用户、手动输入、密码、退出系统。我更喜欢创建按钮,但属性字体不起作用。
我创建了一个 class:
unit uKeyboard;
interface
uses
FMX.Edit, FMX.StdCtrls, FMX.Layouts, SysUtils;
type
TKeyboard = class(TObject)
btnk : array [0..9] of TButton;
btnx : TButton;
btnbs : TButton;
edtk : TEdit;
procedure OnClickB (Sender : TObject);
procedure OnClickX (Sender : TObject );
procedure OnClickBS (Sender : TObject );
public
constructor Create (var GLayout1 : TGridLayout; var EdtText : TEdit);
destructor Destroy; override;
end;
implementation
constructor TKeyboard.Create(var GLayout1: TGridLayout; var EdtText: TEdit);
var
i : Integer;
begin
edtk := EdtText;
GLayout1.ItemWidth := Round(GLayout1.Width/3);
GLayout1.ItemHeight := Round(GLayout1.Height/4);
for i := 9 downto 0 do
begin
btnk[i] := TButton.Create(GLayout1);
with btnk[i] do
begin
Parent := GLayout1;
TextSettings.Font.Size := 40;
Text := IntToStr(i);
OnClick := OnClickB;
end;
end;
...
主单元内部:
uses
uKeyboard, ...;
var
Keyboard : TKeyboard;
// OnClickButton
Keyboard := TKeyboard.Create(GridLayout4,EdtRelease);
字体不是40:
根据文档:
Setting Text Parameters in FireMonkey: Using the StyledSettings Property
When changing text representation properties of the TTextSettings type objects, remember that when you are changing the value of a property (of the
TextSettings.Font.Size
property in the previous example), then the actual changing of the object's view happens only if the ITextSettings.StyledSettings property does not contain the TStyledSetting.Size constant. The "Relation between TStyledSetting constants and TTextSettings properties" table shows which TStyledSetting constants control handling of the TTextSettings text representation properties.
因此,为了给 TButton.TextSettings.Font.Size
设置一个值,您需要从 TButton.StyledSettings
属性 中删除 TStyledSetting.Size
标志,例如:
btnk[i] := TButton.Create(GLayout1);
with btnk[i] do
begin
Parent := GLayout1;
StyledSettings := StyledSettings - [TStyledSetting.Size]; // <-- add this
TextSettings.Font.Size := 40;
Text := IntToStr(i);
OnClick := OnClickB;
end;