vb.net 向winform添加过渡效果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17506981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:10:45  来源:igfitidea点击:

Adding a transition effect to a winform?

vb.netwinforms

提问by Jose M.

I want to know if there is a way that I can add transition effects to my winforms.

我想知道是否有一种方法可以为我的 winform 添加过渡效果。

I have about 3 winforms on my application (vb.net) that open at the top of the screen. My client is concerned with aesthetics, so transitions is one requirements for the forms to show up when called.

我的应用程序 (vb.net) 上有大约 3 个在屏幕顶部打开的 winform。我的客户关心美学,因此转换是表单在调用时显示的要求之一。

Maybe transition is not accurate. What I mean is having the form move from left to right when called. or top to bottom.

也许过渡不准确。我的意思是让表单在调用时从左向右移动。或从上到下。

Are there any resources, to help accomplish this?

是否有任何资源可以帮助实现这一目标?

回答by KekuSemau

The simplest way is to use a Timer and increase Opacity in a few steps over a second or two.

最简单的方法是使用计时器并在一两秒内分几步增加不透明度。

http://msdn.microsoft.com/library/system.windows.forms.form.opacity.aspx

http://msdn.microsoft.com/library/system.windows.forms.form.opacity.aspx

An example:

一个例子:

Form1:

表格1:

Public Class Form1

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim f As Form2
        f = New Form2
        f.Timer1.Enabled = True
        f.Timer1.Interval = 5
        f.Opacity = 0
        f.ShowDialog(Me)
    End Sub

End Class

Form2:

表格2:

Public Class Form2
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If Me.Opacity >= 1 Then
            Timer1.Stop()
            Exit Sub
        End If
        Me.Opacity += 0.05
    End Sub
End Class