With default Windows settings, accelerator keys are not meant to be shown on dialogs until the user presses the ALT key.
德尔福的TLabel
控件不遵守这个约定,如下所示:
Although both label and check box have an accelerator key specified, the check box correctly hides it, but the label does not. Of course, when ALT is pressed, the accelerator shows for the check box, but it's the behaviour prior to that which is incorrect.
我对为什么会发生这种情况的理解是,实现此行为的 VCL 代码包含在TWinControl
,例如UpdateUIState
方法,并依赖于发送底层窗口控件WM_CHANGEUISTATE
信息。自从TLabel
没有窗口化,它错过了这种处理。
任何人都可以建议一种方法来实现非窗口控件所需的行为吗?
Update 1
我刚刚发现组框和单选按钮组也不响应 UI 状态。
Update 2
QC#97044 http://qc.embarcadero.com/wc/qcmain.aspx?d=97044.
我想我已经找到了处理它的方法。
function HideAccelFlag(Control: TControl): Integer;
begin
//ask the top level window about its UI state
while Assigned(Control.Parent) do begin
Control := Control.Parent;
end;
if (Control.Perform(WM_QUERYUISTATE, 0, 0) and UISF_HIDEACCEL)=UISF_HIDEACCEL then begin
Result := DT_HIDEPREFIX;
end else begin
Result := 0;
end;
end;
type
TUIStateAwareLabel = class(TLabel)
protected
procedure DoDrawText(var Rect: TRect; Flags: Longint); override;
end;
procedure TUIStateAwareLabel.DoDrawText(var Rect: TRect; Flags: Integer);
begin
if ShowAccelChar then begin
Flags := Flags or HideAccelFlag(Self);
end;
inherited;
end;
我确保我始终创造TUIStateAwareLabel
而不是TLabel
通过将表单流机制与TReader.OnFindComponentClass
.
处理TCustomGroupBox
后代就更乱了。对于他们,我诉诸于复制源代码TCustomGroupBox.Paint
进入我的后代并利用HideAccelFlag
again.
下一个任务是将其写成质量控制报告。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)