T编辑焦点和插入符
我有两个 TEdit 控件。当我退出 edit1 时, edit2 获得焦点。在我的 Edit1 的 OnExit 事件上 我有以下代码:
procedure TForm1.Edit1Exit(Sender: TObject);
begin
edit2.Enabled := false;
edit2.Enabled := true;
edit2.setfocus;
end;
Edit2 具有焦点。但是,其中没有插入符号。 我可以开始打字,但很混乱,因为我不知道 哪个控件具有焦点。
我更感兴趣的是翻转的效果 导致某些消息不可用的已启用属性 正确射击?例如edit2的OnEnter事件 没有被触发。
如果有什么关系的话,那就是《D2006》了。
感谢您的回复。
I got two TEdit controls. When I tab out of edit1,
edit2 receives the focus. On my OnExit event of Edit1
I have the following code:
procedure TForm1.Edit1Exit(Sender: TObject);
begin
edit2.Enabled := false;
edit2.Enabled := true;
edit2.setfocus;
end;
Edit2 has the focus. However, there is no caret in it.
I can start typing but it's confusing as I do not know
which control has the focus.
I'm more interested on what's with the flipping of the
Enabled property that's causing some messages to be not
firing properly ? For instance edit2's OnEnter event
is not being triggered.
This is on D2006 if it matters at all.
Thanks for the reply.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不明白为什么您禁用并启用
edit2
,但您这样做:顺便说一句,我同意 Andreas Rejbrand 的观点。
I don't understand why you disable and enable
edit2
, but you do this:BTW, I agree with Andreas Rejbrand.
我严重怀疑你正在以错误的方式做某事,最好的解决方案很可能是重新设计。您不应该在控件接收焦点时禁用然后启用该控件。
I seriously suspect you are doing something in a bad way, and the best solution is most likely a redesign. You are not supposed to disable and then enable a control while it is receiving focus.
在前一个活动控件的 OnExit 事件处理程序中包含大量代码不需要需要禁用下一个活动控件。该代码将在下一个活动控件显示插入符号之前执行,并且能够接收用户输入。只需确保它不会通过启动新线程或使用 Application.ProcessMessages 之类的方式传递执行即可。
将
Screen.Cursor
设置为crHourGlass
以使用户清楚地知道下一个活动控件尚未准备好。Having a lot of code in the OnExit event handler of the previous active control does not require to disable the next active control. That code will execute before the next active control shows up the caret and will be able to receive user input. Just make sure that it does nót pass execution over by something like starting a new thread or using
Application.ProcessMessages
.Set
Screen.Cursor
tocrHourGlass
to make it clear for the user that the next active control is not ready yet.当 MainForm 的 OnActive 激活另一个表单时发现问题。
控制焦点已设置但不起作用。我发现的解决方法是发送 PostMessage(Handle, WM_SETFOCUS, 0, 0);到表单句柄。
Found an issue when OnActive for MainForm activates another form.
Control focus is set but does not work. The work around I found was sending PostMessage(Handle, WM_SETFOCUS, 0, 0); to the form handle.