以幻灯片动画全屏显示第二个表单 [英] Display second form as full screen with slide animation

查看:73
本文介绍了以幻灯片动画全屏显示第二个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2种形式的简单应用程序,两种形式都具有以下属性:

I have a simple application that contain 2 forms, both forms has these properties:

BorderStyle := bsnone;
WindowState := wsMaximized;

我将这些属性设置为全屏显示。在主窗体中有一个按钮,当我单击时,我想将第二个窗体显示为带有幻灯片动画的全屏显示,因此我使用了以下代码:

I set these properties to make both of them full screen. In the main form there is a button and when I click I want to show the second form as full screen with slide animation so I used this code:

AnimateWindow(form2.Handle, 500, AW_ACTIVATE OR AW_SLIDE OR AW_HOR_NEGATIVE);

Form2处于自动创建状态,可见属性设置为false。

Form2 is in auto create and visible property is set to false.

尝试此操作时出现的问题是,我看到了奇怪的结果,动画播放,但是form2出现时没有任何控件并且没有覆盖全屏。

The problem when I tried this I saw odd results, the animation play but the form2 appear without any controls and not covering the full screen.

如何解决该问题,以便可以将Form2显示为带有幻灯片动画的全屏显示?

How to fix that so I can display form2 as full screen with slide animation ?

我正在使用XE5

推荐答案

您的问题是,在首次显示Form2之前,VCL不会创建窗口控件的API窗口。因为它不需要。请记住,当您调用 AnimateWindow 时, visible仍设置为false。

Your problem is, before Form2 is first shown, the VCL does not create API windows of the windowed controls. Because it doesn't need to. Remember 'visible' is still set to false when you call AnimateWindow.

以下是一种不太理想的解决方法,当表单的宽度和高度为0时,将其设置为可见。它还解决了另一个我不知道您为什么没有的问题。我根本无法为最大化的窗口制作动画,这对我来说似乎很合理-最大化的窗口不会移动。无论如何,要进行测试,我建议在设计时将'wsNormal'设置为 WindowState

Below is a not very elegant workaround which sets 'visible' while the form has 0 width and height. It also addresses an additional problem which I don't know why you are not having. It is that I cannot animate a maximized window at all, which seems logical to me - a maximized window does not move. Anyway, to test it I suggest setting 'wsNormal' as WindowState at design time.

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Form2.Visible then begin
    Form2.WindowState := wsNormal;
    AnimateWindow(Form2.Handle, 500, AW_HIDE OR AW_SLIDE OR AW_HOR_NEGATIVE);
    Form2.Close;
  end else begin
    Form2.Width := 0;
    Form2.Height := 0;
    Form2.Visible := True;
    ShowWindow(Form2.Handle, SW_HIDE);

    Form2.WindowState := wsNormal;
    Form2.Width := Form2.Monitor.Width;
    Form2.Height := Form2.Monitor.Height;
    AnimateWindow(form2.Handle, 500, AW_ACTIVATE or AW_SLIDE OR AW_HOR_NEGATIVE);
    Form2.WindowState := wsMaximized;
  end;
end;

这篇关于以幻灯片动画全屏显示第二个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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