首先 股票软件很多都是在一个MAINFORM里放多个MDI子窗体
OK问题出来了,当我们使用COMBOBOX控件切换指标的时候 焦点回不到MDI子窗体里了
怎么办呢,
常规做法是
procedure TfmMain.RzComboBox1Change(Sender: TObject);
begin
MDICHILDFORM.SETFOCUS;
end;
问题出来了,焦点回不去。
procedure TCustomForm.SetFocus;
begin
if not FActive then
begin
if not (Visible and Enabled) then
raise EInvalidOperation.Create(SCannotFocus);
SetWindowFocus;
end;
end;
窗体做了什么?
NOT FACTIVE 下才能焦点设置回窗体
procedure TCustomForm.SetWindowFocus;
var
FocusControl: TWinControl;
begin
if (FActiveControl <> nil) and (FDesigner = nil) then
FocusControl := FActiveControl else
FocusControl := Self;
Windows.SetFocus(FocusControl.Handle);
if GetFocus = FocusControl.Handle then
FocusControl.Perform(CM_UIACTIVATE, 0, 0);
end;
解决方法来了
Windows.SetFocus(FocusControl.Handle);
这句足够了 如果有问题加上下边这句,具体干嘛的没查这个消息
FocusControl.Perform(CM_UIACTIVATE, 0, 0);