如何在delphi中运行时更改主窗体? [英] how to change main form at runtime in delphi?

查看:288
本文介绍了如何在delphi中运行时更改主窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在运行时更改mainform。我需要它在用户登录我的应用程序。

I can't change mainform at runtime. I need it for user login in my app.

推荐答案

参考 - 开关Application.Mainform在运行时并调用MainformOnTaskBar导致Windows任务栏上的闪烁 [ ^ ]。

Refer - Switch Application.Mainform at runtime and invoke MainformOnTaskBar cause flickering on Windows Taskbar[^].
引用:

主要形式不是你允许的改变德尔福。你设法找到了一种似乎在中途工作的方法,但这是一个黑客攻击。停止这样做。

The main form isn't something you're allowed to change in Delphi. You managed to find a way that appears to work half-way, but it's a hack. Stop doing that.

一个应用程序只有一个主窗体,它是第一个通过 CreateForm 。如果您需要两种截然不同的主要表单行为,那么您可以尝试几种技巧:

An application has only one main form, and it's the first form that finishes being created via CreateForm. If you need two radically different behaviors for the main form, then you can try a couple of techniques:



  • 将两个主要表单定义为 frames 。把你所有的功能放在那里。然后定义一个单独的表单,作为两个帧之一的父表单。不要切换主窗体,只需破坏框架并用新框架替换它。


  • Define your two main forms as frames. Put all your functionality there. Then define a single form that will act as the parent of one of the two frames. Instead of switching the main form, simply destroy the frame and replace it with a new one.

与框架解决方案类似,但改为使用窗体。创建表单,并将 Parent 属性设置为真正的主表单。这可能会有较低的初始成本,因为你已经拥有这两种形式,但根据我的经验,重新创建表单比使用设计作为子控件的框架更脆弱,所以更喜欢框架技术。

Similar to the frame solution, but use forms instead. Create the forms, and set the Parent property to be the "real" main form. This will probably have a lower initial cost because you already have the two forms, but in my experience, re-parenting forms is more fragile than frames, which were designed for being child controls, so prefer the frame technique.

任务栏上的闪烁来自一个表格消失而另一个表格出现。使用上述任何一种技术,总会有一种形式,而不是两种,所以没有什么可以闪烁。

The flicker on the taskbar comes from one form disappearing and another appearing. With either technique above, there's always just one form, never two, so there's nothing to flicker.



这可能对你有所帮助。


This might help you.


这篇关于如何在delphi中运行时更改主窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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