Animation of words in visual studio

2019-09-17 19:30发布

Question 1

I am working on a WPF application in visual studio 2015.The language is visual basic.I need to animate my logo when the app start.Since i am newbie,i don't know how to animate word.I am hoping to do a sliding effect (like that in word 2016).I am open to all ideas and thanks for your help.

I went online and online and found this in visual basic 6,

Private Sub trmText_Timer()
   If lblCaption.Caption <> StrCap Then
     If lblCaption.Alignment = 0 Then
        'run from left
        lblCaption.Caption = Left(StrCap, Len(lblCaption.Caption) + 1)
     ElseIf lblCaption.Alignment = 1 Then
        'run from right
        lblCaption.Caption = Right(StrCap, Len(lblCaption.Caption) + 1)
     ElseIf lblCaption.Alignment = 2 Then
        'run from the middle
       lblCaption.Caption = Mid(StrCap, Len(StrCap) \ 2 + Len(StrCap) Mod 2 - Num, _
                            2 * (Num + 1) - Len(StrCap) Mod 2)
       Num = Num + 1
     End If
   Else
      lblCaption.Caption = ""
      Num = 0
   End If
End Sub

But it looks old & primitive.Looking for some modern like designs.

Question 2

If i use animated gif's for my logo would it affect my application performance.(which is the reason why i stick to plane text).Any one know any good application to make gif?

Question 3

If i decided to go with gif anyone know how to stop the gif image from repeating itself more than once.(like that of android which swaps multiple images onto screen and stops on the last screen till device boots up ).Can i use the above method to display my logo.if so,how??

Thanks in advance.Any idea is appreciated.

1条回答
迷人小祖宗
2楼-- · 2019-09-17 20:13

Try using a DoubleAnimation to animate a render transform for your text. In this example, I use 2 Labels on my Window. This code animates the X property of the TranslateTransform of each label from offscreen to onscreen. In addition, the second label doesn't begin animating until the first has completed. When the window is shown, the title label will come in from the left and then the sub-title label will come in the same way. You can play with the values to suit your needs.

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="300" Width="400">
    <Grid>
        <Label Foreground="Red" FontSize="72" FontWeight="Bold">Title
            <Label.RenderTransform>
                <TranslateTransform x:Name="TitleLeftToRight"/>
            </Label.RenderTransform>
            <Label.Triggers>
                <EventTrigger RoutedEvent="Label.Loaded">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation DecelerationRatio="1.0" Storyboard.TargetName="TitleLeftToRight" Storyboard.TargetProperty="X" From="-300" To="100" Duration="00:00:00.5" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Label.Triggers>
        </Label>
        <Label Foreground="Blue" FontSize="24" Margin="0,85,0,0">Sub Title
            <Label.RenderTransform>
                <TranslateTransform x:Name="SubTitleLeftToRight" X="-200"/>
            </Label.RenderTransform>
            <Label.Triggers>
                <EventTrigger RoutedEvent="Label.Loaded">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation DecelerationRatio="1.0" Storyboard.TargetName="SubTitleLeftToRight" Storyboard.TargetProperty="X" From="-300" To="125" BeginTime="0:0:0.5" Duration="00:00:00.5" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Label.Triggers>
        </Label>
    </Grid>
</Window>
查看更多
登录 后发表回答