如何“父母”形式? (控件将不接受焦点) [英] How to 'parent' a form? (Controls won't accept focus)

查看:84
本文介绍了如何“父母”形式? (控件将不接受焦点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子表格 frmTest和一个主表格 TfrmMain。我将主窗体设置为frmTest的父窗体,如下所示:

I have a child form 'frmTest' and a main form 'TfrmMain'. I set the main form as parent for frmTest like this:

unit Main;

INTERFACE
USES
  System.SysUtils, System.Classes, Vcl.Forms, Test, Vcl.StdCtrls, Vcl.Controls;

type
  TfrmMain = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

IMPLEMENTATION  {$R *.dfm}

procedure TfrmMain.Button1Click(Sender: TObject);
VAR frmTest: TChildForm;
begin
  Application.CreateForm(TChildForm, frmTest);
  //frmTest:= TForm1.Create(Self);
  frmTest.Parent:= Self;
  frmTest.Show;
  frmTest.SetFocus;
end;







unit test;  { THIS IS THE CHILD }

INTERFACE

USES
  System.SysUtils,  System.Classes, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin;

TYPE
  TChildForm = class(TForm)
    Edit1: TEdit;
    SpinEdit1: TSpinEdit;
  private
  public
  end;


IMPLEMENTATION {$R *.dfm}

end.

代码为ZIP

但是frmInsertImg中的控件(编辑框,旋转编辑等)将不接受鼠标的焦点

But controls (edit box, spin edit, etc) in frmInsertImg will not accept focus from mouse but can be focused with Tab.

我在做什么错了?

推荐答案

我建议您将子窗体的 BorderStyle 设置为 bsNone 。我不确定这样做的确切原因,但效果是否理想。

I suggest that you set BorderStyle to bsNone for the child form. I'm not sure of the exact reasons why this works, but it has the desired effect.

如果您需要为子表单添加视觉框架,那就是

If you need to add a visual frame for your child form then that is best done with explicit UI for the contained of your child form.

在我看来,表单并不是真正打算以这种方式使用的。您可以使大多数情况下都可以正常工作,但是它并不十分强大。将UI放入框架中,然后进行托管,可以带来更好的行为。

Forms aren't really intended to be used in this way, in my opinion. You can make things mostly work, but it's not terribly robust. Putting the UI into a frame and then hosting that should lead to better behaviour.

这篇关于如何“父母”形式? (控件将不接受焦点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆