父组件显示在子窗体上

发布于 2025-01-09 18:20:56 字数 740 浏览 1 评论 0原文

我一直在关注以下页面,以便获得一个子表单,我可以单击其组件(例如编辑)并获得适当的焦点:

在 Delphi 中使用 MDI 表单

现在的问题是父表单上的组件显示在顶部子表单的。如果我对这些组件使用 SendToBack() 命令,它们就会完全消失。以下是所发生情况的屏幕截图:

image

编辑:
我有一个带有按钮的表单和一个显示客户信息的 ListView。当我单击某个客户端时,我可以单击一个按钮来查看或编辑该客户端,或者添加一个新客户端。编辑/添加会弹出一个表单,我可以在其中输入信息并保存。我为每个具有 SetFocus() 的编辑使用 OnClick 事件。这将焦点集中在每个编辑上,但随后所有文本都被选中,因此我无法单击该行并开始编辑文本 - 它只会覆盖,除非我先使用箭头。

最初,我使用常规表单,这就是我遇到的焦点问题。 MDI 修复了这个问题,但现在父组件显示在子组件之上。

I've been following the below page in order to have a child Form that I can click on its components (such as an edit) and have proper focus:

Working with MDI Forms in Delphi

The problem now is that the components on the parent Form show on top of the child Form. If I use the SendToBack() command for those components, they completely disappear. Here is a screenshot of what happens:

image

EDIT:
I have a Form with buttons and a ListView that displays client info. When I click on a client, I can click a button to view or edit that client, alternatively add a new one. The Edit/Add pops up a Form where I can input the info and save it. I'm using an OnClick event for each Edit that has a SetFocus(). That gets focus on each Edit, but then all the text is selected, so I cannot click on the line and start editing text - it just overrides unless I use an arrow first.

Initially, I used regular Forms and that's where I had the focus issue. MDI fixed that, but now it's the parent components that show on top of the child.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不一样的天空 2025-01-16 18:20:56

关于 MDI 形式:这就是 MDI 的工作原理。主窗体除了菜单栏和可选的工具栏(可选)之外不应有任何其他内容,并与 alTop 对齐。子窗体使用其余空间。正如@RemyLebeau 建议的那样,如果对齐它们,您也可以添加其他控件。

但事实证明,使用普通辅助表单的实际问题是,当您通过单击按钮将焦点设置到编辑控件时,辅助表单上的编辑控件中的文本将被选中。在将焦点设置到编辑控件后,这很容易更改:

Edit2.SelLength := 0; // nothing selected, cursor at beginning

Edit3.SelStart := Length(Edit3.Text); // nothing selected, cursor at end of text

Concerning MDI forms: that is how MDI works. The main form is not supposed to have anything else than a menu bar and optionally a toolbar, aligned alTop. The child forms use the rest of the space. Well as @RemyLebeau suggested, you can add other controls too, if you align them.

But it turned out that the actual problem with using ordinary secondary forms was that the text in an edit control on the secondary form becomes selected when you set focus to the edit control in a button click. That is easy to change, right after you set the focus to an edit control:

Edit2.SelLength := 0; // nothing selected, cursor at beginning

Edit3.SelStart := Length(Edit3.Text); // nothing selected, cursor at end of text
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文