动画闪烁效果C#
我正在做一个项目,我只是想让屏幕闪烁 我以前从未编写过C#代码或使用过VisualStudio,所以我不知道自己在做什么 我刚刚完成了一个javascript版本,你可以在这里看到 我已附加VS项目文件 下面是我目前在xaml.cs文件中得到的内容动画闪烁效果C#,c#,wpf,animation,C#,Wpf,Animation,我正在做一个项目,我只是想让屏幕闪烁 我以前从未编写过C#代码或使用过VisualStudio,所以我不知道自己在做什么 我刚刚完成了一个javascript版本,你可以在这里看到 我已附加VS项目文件 下面是我目前在xaml.cs文件中得到的内容 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Sy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private static System.Timers.Timer testTimer;
public MainWindow()
{
InitializeComponent();
testTimer = new System.Timers.Timer(5000); // 5 seconds
testTimer.Elapsed += new ElapsedEventHandler(OnTimerElapsed);
testTimer.Interval = 5000;
testTimer.Enabled = true;
}
public void OnTimerElapsed(object source, ElapsedEventArgs e)
{
this.Dispatcher.Invoke((Action)(() =>
{
b1.Height = 420;
b2.Height = 420;
}));
this.Dispatcher.Invoke((Action)(() =>
{
b1.Height = 0;
b2.Height = 0;
System.Threading.Thread.Sleep(100);
}));
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用系统计时器;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间WpfApplication3
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
专用静态系统。定时器。定时器测试定时器;
公共主窗口()
{
初始化组件();
testTimer=new System.Timers.Timer(5000);//5秒
testTimer.Appeased+=新的ElapsedEventHandler(OnTimeRecursed);
testTimer.Interval=5000;
testTimer.Enabled=true;
}
公共void onTimeRecursed(对象源,ElapsedEventArgs e)
{
this.Dispatcher.Invoke((操作)(()=>
{
b1.高度=420;
b2.高度=420;
}));
this.Dispatcher.Invoke((操作)(()=>
{
b1.高度=0;
b2.高度=0;
系统线程线程睡眠(100);
}));
}
}
}
这是我在主窗口中看到的。xaml
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="1440"
Name="Winda" AllowsTransparency="True" WindowStyle="None"
Opacity="1" Topmost="True" WindowStartupLocation="CenterScreen"
WindowState="Maximized" IsHitTestVisible="False" ShowInTaskbar="False" Background="Transparent">
<Grid>
<Rectangle Fill="Black" HorizontalAlignment="Left" Height="0" Stroke="Black" VerticalAlignment="Top" Width="1440" Stretch="Fill" Name="b1"/>
<Rectangle Fill="Black" HorizontalAlignment="Left" Height="0" Stroke="Black" VerticalAlignment="Bottom" Width="1440" Margin="0" Stretch="Fill" Name="b2"/>
</Grid>
</Window>
从JavaScript演示中,我希望您能看到我正在尝试做什么。因此,任何帮助都将不胜感激
谢谢。你可以看看c语言中的图形类,看看这里:你可以看看c语言中的图形类,看看这里:
<Window x:Class="MiscSamples.BlinkingWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ScreenBlink" Height="300" Width="300">
<Window.Resources>
<Storyboard x:Key="Storyboard" Duration="00:00:05.10" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Trans1" Storyboard.TargetProperty="ScaleY">
<DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<DiscreteDoubleKeyFrame KeyTime="00:00:04.99" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:05" Value="1"/>
<EasingDoubleKeyFrame KeyTime="00:00:05.1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Trans2" Storyboard.TargetProperty="ScaleY">
<DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<DiscreteDoubleKeyFrame KeyTime="00:00:04.99" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:05" Value="1"/>
<EasingDoubleKeyFrame KeyTime="00:00:05.1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource Storyboard}"/>
</EventTrigger.Actions>
</EventTrigger>
</Window.Triggers>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Rectangle Fill="Black">
<Rectangle.RenderTransform>
<ScaleTransform ScaleY="0" x:Name="Trans1"/>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Fill="Black" Grid.Row="1" RenderTransformOrigin="0.5,1.0">
<Rectangle.RenderTransform>
<ScaleTransform ScaleY="0" x:Name="Trans2"/>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
</Window>
using System.Windows;
namespace MiscSamples
{
public partial class BlinkingWindow : Window
{
public BlinkingWindow()
{
InitializeComponent();
}
}
}