wpf 字幕动画切换
我用timer计时,在第25秒切换另一个字幕,但是结果动画有点卡住了,显示位置也不正确。过10多少之后才正常
代码如下
//上翻跑马灯
private void playY()
{
this.story = new Storyboard();
this.story2 = new Storyboard();
this.marquee.Background = Brushes.Pink;
this.marquee2.Background = Brushes.Green;
this.grid.Background = Brushes.Yellow;
int intRuntime = 1;
this.textHeight = this.MeasureTextHeight();
this.marquee.Height = this.textHeight;
this.marquee2.Height = this.textHeight;
this.grid.Height = this.textHeight;
marquee2.Content = marquee.Content;
this.rowHeight = this.textHeight;
this.playFrom = this.rowHeight;
this.playTo = 0;
DoubleAnimation animation = new DoubleAnimation();
animation.Duration = TimeSpan.FromSeconds(intRuntime);
animation.From = this.playFrom;
animation.To = this.playTo;
Storyboard.SetTargetName(animation, "lab");
Storyboard.SetTargetProperty(animation, new PropertyPath(TranslateTransform.YProperty));
this.story.Duration = TimeSpan.FromSeconds(intRuntime);
this.story.Children.Add(animation);
this.story.FillBehavior = FillBehavior.Stop;
this.story.Completed += new EventHandler(story_Completed);
this.story.Begin(this, true);
this.playFrom2 = this.playFrom + this.textHeight;
this.playTo2 = this.playFrom2 - this.rowHeight;
DoubleAnimation animation2 = new DoubleAnimation();
animation2.Duration = TimeSpan.FromSeconds(intRuntime);
animation2.From = playFrom2;
animation2.To = playTo2;
Storyboard.SetTargetName(animation2, "lab2");
Storyboard.SetTargetProperty(animation2, new PropertyPath(TranslateTransform.YProperty));
this.story2.Duration = TimeSpan.FromSeconds(intRuntime);
this.story2.Children.Add(animation2);
this.story2.FillBehavior = FillBehavior.Stop;
this.story2.Completed += new EventHandler(story2_Completed);
this.story2.Begin(this, true);
}
代码如下
//上翻跑马灯
private void playY()
{
this.story = new Storyboard();
this.story2 = new Storyboard();
this.marquee.Background = Brushes.Pink;
this.marquee2.Background = Brushes.Green;
this.grid.Background = Brushes.Yellow;
int intRuntime = 1;
this.textHeight = this.MeasureTextHeight();
this.marquee.Height = this.textHeight;
this.marquee2.Height = this.textHeight;
this.grid.Height = this.textHeight;
marquee2.Content = marquee.Content;
this.rowHeight = this.textHeight;
this.playFrom = this.rowHeight;
this.playTo = 0;
DoubleAnimation animation = new DoubleAnimation();
animation.Duration = TimeSpan.FromSeconds(intRuntime);
animation.From = this.playFrom;
animation.To = this.playTo;
Storyboard.SetTargetName(animation, "lab");
Storyboard.SetTargetProperty(animation, new PropertyPath(TranslateTransform.YProperty));
this.story.Duration = TimeSpan.FromSeconds(intRuntime);
this.story.Children.Add(animation);
this.story.FillBehavior = FillBehavior.Stop;
this.story.Completed += new EventHandler(story_Completed);
this.story.Begin(this, true);
this.playFrom2 = this.playFrom + this.textHeight;
this.playTo2 = this.playFrom2 - this.rowHeight;
DoubleAnimation animation2 = new DoubleAnimation();
animation2.Duration = TimeSpan.FromSeconds(intRuntime);
animation2.From = playFrom2;
animation2.To = playTo2;
Storyboard.SetTargetName(animation2, "lab2");
Storyboard.SetTargetProperty(animation2, new PropertyPath(TranslateTransform.YProperty));
this.story2.Duration = TimeSpan.FromSeconds(intRuntime);
this.story2.Children.Add(animation2);
this.story2.FillBehavior = FillBehavior.Stop;
this.story2.Completed += new EventHandler(story2_Completed);
this.story2.Begin(this, true);
}
...全文
相关推荐
C# 滚动字幕 实例源码(窗体技巧)
**扩展功能**:还可以添加其他功能,比如速度调节、滚动方向切换、文本对齐方式等,以增强用户体验。这个C#滚动字幕实例源码提供了创建滚动字幕的基本框架,开发者可以根据自己的需求进行修改和扩展。
WPF视频播放器
此外,可能还包含了对字幕的支持,使用户能够在观看视频时显示字幕内容,提高观看体验。集成此播放器到自己的项目中,开发者需要理解WPF的控件绑定、事件处理和命令机制。
C#实现滚动字幕完整源码
考虑优化:为了提高用户体验,可以添加暂停、继续、切换字幕等功能。还可以自定义滚动动画,比如匀速滚动、加速滚动、减速滚动等,通过调整Timer的Interval或滚动距离来实现。5.
Textmyvideo:用于在视频中添加字幕的网站
多语言支持:考虑到字幕的需求,Textmyvideo可能有内置的多语言支持,允许用户切换字幕语言。8.
WPF 播放器
在播放器中,某些功能可能根据用户需求动态显示或隐藏,例如全屏切换按钮、字幕选项等。3. **媒体播放** WPF提供了`MediaElement`控件来实现音频和视频播放。


