简体   繁体   English

通过幻灯片过渡显示表单

[英]Make a Form show with a Slide Transition

For my application, When showing new forms, I would like for there to be a transition slide when they appear somewhat similar to how Tab items can appear with slide transitions - well, actually in the same manner. 对于我的应用程序,当显示新表单时,我希望有一个过渡幻灯片,当它们看上去与Tab项在幻灯片过渡中的显示方式有些相似时-实际上,是相同的方式。

I am unable to find any troubleshooting or examples surrounding the specific matter. 我找不到有关特定问题的任何故障排除或示例。 The only work around I can think of is just using a tab control for all three forms and placing them within the tab control. 我能想到的唯一解决方法是对所有三种表单都使用选项卡控件,并将它们放置在选项卡控件中。

I have also tried Form.animateFloatWait() function as one would normally do with controls on forms, but to no avail. 我也尝试过Form.animateFloatWait()函数,就像通常使用表单控件一样,但无济于事。

How do I get my forms to slide in view? 如何使表格在视图中滑动?

With RAD Studio XE5, either Delphi or C++ Builder, the form is fullScreen displayed. 使用DEL Studio或C ++ Builder的RAD Studio XE5,该窗体将全屏显示。

Therefore, if we need to make some effect with slide transition, we need to use TPanel for perfect performance: 因此,如果我们需要在幻灯片过渡上产生一些效果,则需要使用TPanel以获得完美的性能:

  1. Add an TPanel, make it as fullsize, and do not use align to do so. 添加一个TPanel,使其为全尺寸,并且不要使用align这样做。 We need to initalize the position and size of TPanel in FormCreate method. 我们需要在FormCreate方法中初始化TPanel的位置和大小。

  2. Create second TPanel for the form, not let second TPanel be child of first TPanel. 为表单创建第二个TPanel,不要让第二个TPanel作为第一个TPanel的子级。 Initialize the position and size of the second TPanel, make sure it is placed in the right side of screen. 初始化第二个TPanel的位置和大小,确保将其放置在屏幕的右侧。

FormCreate method: FormCreate方法:

procedure TFormMainView.FormCreate(Sender: TObject);
var
 newLocation : TPosition;
begin
  newLocation := self.btnLogin.Position;
  newLocation.X := screen.Size.Width - self.btnLogin.Width - 5;
  self.btnLogin.Position := newLocation;

  self.PanelMainView.Position.X := 0;
  self.PanelMainView.Position.Y := 0;
  self.PanelMainView.Width := screen.Size.Width;
  self.PanelMainView.Height := screen.Size.Height;

  self.PanelLogin.Position.X := screen.Size.Width;
  self.PanelLogin.Position.Y := 0;
  self.PanelLogin.Width := screen.Size.Width;
  self.PanelLogin.Height := screen.Size.Height;
end;

With Screen.Size, we can make sure the TPanel can fit various size of device, say, Android Phones. 使用Screen.Size,我们可以确保TPanel可以适合各种尺寸的设备,例如Android Phone。 And set a button on first and second view, to toggle the slide animation (button on 1st Panel to toggle the animation to slide to left, and button on 2nd Panel to toggle the animation to slide to right.) 并在第一个和第二个视图上设置一个按钮,以切换幻灯片动画(第一个面板上的按钮将动画切换到左侧,第二个面板上的按钮将动画切换到右侧。)

Let's name the button on 1st Panel as btnLogin, so the method to handle the btnLoginClick event is: ATTENTION: FloatAnimation1 is for 2nd Panel, FloatAnimation2 is for 1st Panel, and the "Property Name" of both TFloatAnimation is "Position.X", this will make the animation on the X axis: 让我们将第一个面板上的按钮命名为btnLogin,因此处理btnLoginClick事件的方法是:注意:FloatAnimation1代表第二个面板,FloatAnimation2代表第一个面板,并且两个TFloatAnimation的“属性名称”都是“ Position.X”,这将使动画在X轴上:

procedure TFormMainView.btnLoginClick(Sender: TObject);
begin
   self.FloatAnimation2.StartValue := 0;
   self.FloatAnimation2.StopValue := -1 * screen.Size.Width;

   self.FloatAnimation1.StartValue := screen.Size.Width;
   self.FloatAnimation1.StopValue := 0;

   self.FloatAnimation2.start;
   self.FloatAnimation1.Start;
end;

The button of 2nd Panel named "btnBacktoMainView", and the event handler is: 第二个面板的按钮名为“ btnBacktoMainView”,事件处理程序为:

procedure TFormMainView.btnBackToMainScreenClick(Sender: TObject);
begin
   self.FloatAnimation1.StartValue := self.PanelLogin.Position.X;
   self.FloatAnimation1.StopValue := self.PanelLogin.Position.X + self.PanelLogin.Width;

   self.FloatAnimation2.StartValue := self.PanelMainView.Position.X;
   self.FloatAnimation2.StopValue := self.PanelMainView.Position.X + self.PanelMainView.Width;

   self.FloatAnimation1.Start;
   self.FloatAnimation2.Start;
end;

See? 看到? what we did is to set the "statValue", "StopValue" of animation object, and invoke the start method, the Panel slide so great. 我们要做的是设置动画对象的“ statValue”,“ StopValue”,并调用start方法,Panel幻灯片是如此出色。

Maybe this way is not the best way to make view transition, but it works, and perform perfect. 也许这种方法不是进行视图过渡的最佳方法,但它可以正常工作并表现完美。 I used to use similar way to handle more than one view in Win32 application in this 10 years, and the effect is good. 在过去的10年中,我曾经使用类似的方式在Win32应用程序中处理多个视图,效果很好。

The only difference is that I have to use TTimer and Application.ProcessMessage to make sure the animation in Win32 work. 唯一的区别是我必须使用TTimer和Application.ProcessMessage来确保Win32中的动画正常工作。 (Form project, of course). (当然是表格项目)。

And I tested this way in XE5 for either iOS or Android, and work in either platform. 我在XE5中针对iOS或Android进行了这种测试,并且可以在两种平台上使用。 Share with everybody. 与大家分享。

You might just try brute force. 您可能只是尝试蛮力。 IE. IE浏览器 A for-loop that resizes a panel until it fills the required area. 一个for循环,用于调整面板的大小,直到其填充所需的区域。 I haven't worked very much with animated controls, but I've played around a bit with VCL controls from TMS software ( http://www.tmssoftware.com/site/advsmoothtilelist.asp ). 我在动画控件方面工作不多,但是我在TMS软件( http://www.tmssoftware.com/site/advsmoothtilelist.asp )的VCL控件中做了一些工作。 They might have something you could use. 他们可能有您可以使用的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM