- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个面板,其中有几个水平放置的TRadioButton
。如果最左边的按钮获得焦点并且我按向左箭头,则焦点会跳转到最右边的按钮。我想在所有箭头到达边缘时停止这种行为。是否可以 ?我尝试覆盖 WM_KEYDOWN
但当按下箭头键时按钮永远不会收到此消息。
TRadioButton = class(StdCtrls.TRadioButton)
protected
procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
procedure WMKeyUp(var Message: TWMKeyUp); message WM_KEYUP;
public
BlockLeft, BlockRight: Boolean;
constructor Create(AOwner: TComponent); override;
end;
constructor TRadioButton.Create(AOwner: TComponent);
begin
inherited;
BlockLeft:= False;
BlockRight:= False;
end;
procedure TRadioButton.WMKeyDown(var Message: TWMKeyDown);
begin
if BlockLeft and (Message.CharCode = VK_LEFT) then Exit;
if BlockRight and (Message.CharCode = VK_RIGHT) then Exit;
inherited;
end;
procedure TRadioButton.WMKeyUp(var Message: TWMKeyUp);
begin
if BlockLeft and (Message.CharCode = VK_LEFT) then Exit;
if BlockRight and (Message.CharCode = VK_RIGHT) then Exit;
inherited;
end;
最佳答案
VCL 将键盘消息偏移为控件通知并将其发送到消息的目标控件。因此,您应该拦截 CN_KEYDOWN
消息。
如果这是一次性设计考虑,我更愿意在表单级别处理此行为,因为 IMO 控件本身不应该关心它放置在哪里。对于所有单选按钮都应表现相似的表单,示例如下:
procedure TForm1.CMDialogKey(var Message: TCMDialogKey);
begin
if ActiveControl is TRadioButton then
case Message.CharCode of
VK_LEFT, VK_UP: begin
if ActiveControl.Parent.Controls[0] = ActiveControl then begin
Message.Result := 1;
Exit;
end;
end;
VK_RIGHT, VK_DOWN: begin
if ActiveControl.Parent.Controls[ActiveControl.Parent.ControlCount - 1]
= ActiveControl then begin
Message.Result := 1;
Exit;
end;
end;
end;
inherited;
end;
如果这不是一次性行为,我会像维多利亚在问题评论中提到的那样编写一个容器控件。
关于delphi - 如何阻止 TRadioButton 对方向键使用react?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51307893/
我有一个面板,其中有几个水平放置的TRadioButton。如果最左边的按钮获得焦点并且我按向左箭头,则焦点会跳转到最右边的按钮。我想在所有箭头到达边缘时停止这种行为。是否可以 ?我尝试覆盖 WM_K
我使用的是delphi 2010 最佳答案 我同意 Andreas 和 Serg 的观点,即启用主题时控件是透明的。 我曾经尝试过在项目选项中未启用运行时主题或使用操作系统选择经典主题时使复选框透明;
我想要动态创建具有固定宽度的复选框和单选按钮(在 FMX 中,而不是 VCL),以根据其包含的文本更改其高度。我的复选框和单选按钮启用了 WordWrap。所以我想在启用 AutoSize 和 Wor
mybox.Checked := true; 将 TRadioButton 设置为选中(通过代码)会导致调用 OnClick 事件处理程序。 如何识别用户是否通过 GUI 交互进行状态更改 最佳答案
我不知道我的问题是什么,但我无法在 DEx2 中为 TCheckBox、TRadioButton、TGroubBox 和 TRadioGroup 等控件设置字体颜色。我是在 IDE 中还是以编程方式执
我是一名优秀的程序员,十分优秀!