【发布时间】:2020-12-01 03:13:21
【问题描述】:
在 Delphi 10.4 中,在 VCL 应用程序中,使用 TApplicationEvents 组件的 OnMessage 事件处理程序,我增加了右键单击控件的字体大小:
procedure TformMain.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
ThisControl: TControl;
begin
if (Msg.Message = WM_RBUTTONDOWN) then
begin
ThisControl := FindDragTarget(Mouse.CursorPos, True);
CodeSite.Send('TformMain.ApplicationEvents1Message: RIGHTCLICK!', ThisControl.Name);
if ThisControl is TLabel then
TLabel(ThisControl).Font.Size := TLabel(ThisControl).Font.Size + 1
else if ThisControl is TCheckBox then
TCheckBox(ThisControl).Font.Size := TCheckBox(ThisControl).Font.Size + 1;
// ETC. ETC. ETC.! :-(
end;
end;
这是一种极其低效的方法,因为我必须枚举所有现有的控件类型,因为TControl 没有TFont 属性。
更好的方法是获取控件的TFont 属性,而不必询问类型,然后必须对控件进行类型转换。
但是怎么做呢?
【问题讨论】:
标签: delphi object-type delphi-10.4-sydney