gpt4 book ai didi

delphi - TCustomControl 如何接收输入焦点?

转载 作者:行者123 更新时间:2023-12-03 15:20:42 25 4
gpt4 key购买 nike

我正在编写一个基于 TCustomControl 的网格控件,这样我就可以自己处理所有结构、绘画和导航。我似乎无法弄清楚的是:

在我的构造函数中,我将 ControlStyle 设置为:

ControlStyle := ControlStyle + [csCaptureMouse, csClickEvents,
csDoubleClicks, csNeedsBorderPaint, csPannable];

这个想法是,如果控件处理鼠标事件,我可以执行诸如设置选择之类的操作。我注意到控件从未获得焦点。我碰巧在表单上有一个 TComboBox,并且在创建表单时它显然是焦点。无论我在网格中单击多少次,焦点都会保留在组合框上。

这当然也对我处理键盘事件有影响。

那么问题是,当您单击某个控件时,如何确定焦点应该转移到该控件上?

最佳答案

当单击 CustomControl 时,它应该自行调用 SetFocus。

procedure TMyCustomControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;

if not (csDesigning in ComponentState) and CanFocus then
SetFocus;

关于delphi - TCustomControl 如何接收输入焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1398578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com