在启动画面 vb.net 中使用动画 gif
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23568172/
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
Using animated gif in splash screen vb.net
提问by Kat
I'm having trouble creating a .gif be animated in my already created visual studio 2013 project.
我在我已经创建的 Visual Studio 2013 项目中创建 .gif 动画时遇到问题。
Been looking online a bit for the "proper" way to do it. Following this MSDN question: LinkI copied some of the code to see how it would work. I've also seen references to using a timer.
一直在网上寻找“正确”的方式来做到这一点。按照这个 MSDN 问题:链接我复制了一些代码以查看它是如何工作的。我还看到了使用计时器的参考资料。
Public Not Inheritable Class SplashScreen
Private progressGifPath As String = "C:\Documents\Visual Studio 2013\Projects\CameraFinder\icons" + "\orangeLoading.gif"
Private _AnimatedGif As New Bitmap(progressGifPath)
Private m_IsAnimating As Boolean
Public Property IsAnimating() As Boolean
Get
Return m_IsAnimating
End Get
Set(ByVal value As Boolean)
m_IsAnimating = value
End Set
End Property
Private Sub VICameraFinderLoading_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Set up the dialog text at runtime according to the application's assembly information.
If My.Application.Info.Title <> "" Then
Else
End If
End Sub
Private Sub PlayGIF()
If Not m_IsAnimating Then
ImageAnimator.Animate(_AnimatedGif, New EventHandler(AddressOf Me.OnFrameChanged))
m_IsAnimating = True
End If
End Sub
Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
If m_IsAnimating Then
ImageAnimator.UpdateFrames()
Dim aGraphics As Graphics = PictureBox.CreateGraphics
aGraphics.DrawImage(_AnimatedGif, New Point(30, 30))
aGraphics.Dispose()
End If
End Sub
End Class
So I tried this, but I don't see anything on the picture box drawn (I confirmed to see it was brought to the front). And apparently there can be a size limit to the gif included. Any ideas on what would be the better way to include it?
所以我尝试了这个,但是我在绘制的图片框上看不到任何东西(我确认看到它被带到了前面)。显然,包含的 gif 可能有大小限制。关于包含它的更好方法的任何想法?
Thanks!
谢谢!
回答by Kat
Figured it out. I hadn't set the image of the picture box to the gif.
弄清楚了。我没有将图片框的图像设置为 gif。
EDIT:
编辑:
To clarify, the code above wasn't the problem at all. I actually didn't need it in any way. I removed it from the splash screen class, completely. The solution was to go into my picture box's property (F4) and set the backgroundImage to the .gif's filepath (thus importing it as an embedded resource). Doing so has allowed for animation in the splash screen.
澄清一下,上面的代码根本不是问题。我实际上并不需要它。我完全从启动画面类中删除了它。解决方案是进入我的图片框的属性 (F4) 并将 backgroundImage 设置为 .gif 的文件路径(从而将其作为嵌入式资源导入)。这样做允许在初始屏幕中显示动画。

