当我的表单显示时,Windows Vista 和 7 运动效果仅应用一次。为什么?

发布于 2024-10-08 10:43:01 字数 160 浏览 3 评论 0原文

我创建了一个包含两种表单的应用程序。第一个是主要形式,第二个是隐藏形式。 我在 Form1 上放置了一个按钮,并将其设为 ShowModal 作为第二个窗体。在 Win7 上,窗体会显示动画。然后我关闭出现的表单(Form2)并再次单击该按钮。 Form2 出现时没有动画。我每次都想要动画。我应该怎么办?

I created an application with two forms. First one is the main form and second one is hidden.
I placed a button on Form1 and I made it ShowModal the second form. On Win7 the form appears with an animation. Then I close the appeared form (Form2) and I click the button once again. Form2 appears without the animation. I want the animation every time. What should I do?

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

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

发布评论

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

评论(3

初吻给了烟 2024-10-15 10:43:01

我现在唯一能想到的就是每次要以模态方式显示表单时手动创建表单。为此,请转到项目选项并确保不会自动创建表单。然后做

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TForm2.Create(self) do
    try
      ShowModal;
    finally
      Free;
    end;
end;

在我看来,大多数情况下模态表单实际上应该手动创建。

The only thing I can think of right now is to create the form manually each time you want to display it modally. To do this, go to the project options and make sure that the form isn't automatically created. Then do

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TForm2.Create(self) do
    try
      ShowModal;
    finally
      Free;
    end;
end;

In my opinion, most often modal forms should in fact be created manually.

听风吹 2024-10-15 10:43:01

好吧,你可以选择不担心它!或者,一个非常快速的技巧是在每次关闭时释放表单,因为动画似乎仅在第一次显示表单时运行。

编辑:另一种方法是在表单关闭时调用 DestroyHandle。我现在猜测,但我想象 Windows 在窗口中的某个位置记录了一个标志,表明动画已显示。一旦设置了该标志,动画就不会再显示。

Well, you could just elect not to worry about it! Alternatively a very quick hack would be to free the form each time it closes since the animation appears to run only on the first time the form is shown.

EDIT: Another approach would be to call DestroyHandle on your form whenever it closes. I'm guessing now, but I imagine that Windows records somewhere in the window a flag indicating that the animation has been shown. Once this flag has been set the animation is never shown again.

待"谢繁草 2024-10-15 10:43:01

作为一种替代方法,可以通过发送表单样式已更改的通知来欺骗窗口,这将使窗口重置当前表单句柄的“秘密标志”。因此,在显示已创建的表单时,将再次应用很酷的显示效果动画。但是,我不能说这样做会造成什么负面影响。

uses
  Winapi.Windows, Vcl.Controls;

type
  TFormHelper = class helper for TForm
  public
    procedure Show;
  end;

implementation

procedure TFormHelper.Show;
begin
  SendMessage(Handle,CM_CUSTOMSTYLECHANGED,0,0);
  inherited Show;
end;

注意:具有类帮助器的代码,此功能/关键字可能在较旧的 IDE 中不可用。

As an alternative way it's possible to fool windows by sending a notification that form's style has been changed, that will make windows reset "secret flag" for current form's handle. Thus, on showing already created form the cool show effect animation will be applied again. However, I can't say what negative effects can be caused by doing this way.

uses
  Winapi.Windows, Vcl.Controls;

type
  TFormHelper = class helper for TForm
  public
    procedure Show;
  end;

implementation

procedure TFormHelper.Show;
begin
  SendMessage(Handle,CM_CUSTOMSTYLECHANGED,0,0);
  inherited Show;
end;

Note: code featured with a class helper, this feature/keyword might be not available in older IDEs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文