c#实现图片的平移和旋转示例代码
前言
本文主要给大家分享了关于利用c#实现图片的平移和旋转的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧
方法如下
1新建文件夹,添加一个图片
2添加控件两个button控件一个image控件一个Canvas控件
3代码实现
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Data;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Animation;
usingSystem.Windows.Media.Imaging;
usingSystem.Windows.Navigation;
usingSystem.Windows.Shapes;
namespaceWpfApplication16
{
///
///MainWindow.xaml的交互逻辑
///
publicpartialclassMainWindow:Window
{
publicMainWindow()
{
InitializeComponent();
}
privatevoidbutton_Click(objectsender,RoutedEventArgse)
{
DoubleAnimationda=newDoubleAnimation();
da.From=0;
da.To=-100;
Storyboardboard=newStoryboard();
Storyboard.SetTarget(da,image);
Storyboard.SetTargetProperty(da,newPropertyPath(Canvas.LeftProperty));
board.Children.Add(da);
board.Begin();
}
privatevoidxuanzhuan()
{
RotateTransformtotate=newRotateTransform();
image.RenderTransform=totate;
image.RenderTransformOrigin=newPoint(0.5,0.5);
DoubleAnimationda=newDoubleAnimation(0,360,newDuration(TimeSpan.FromMilliseconds(500)));
Storyboardboard=newStoryboard();
Storyboard.SetTarget(da,image);
Storyboard.SetTargetProperty(da,newPropertyPath("RenderTransform.Angle"));
da.RepeatBehavior=RepeatBehavior.Forever;
da.Completed+=Da_Completed;
board.Children.Add(da);
board.Begin();
}
privatevoidDa_Completed(objectsender,EventArgse)
{
}
privatevoidbutton1_Click(objectsender,RoutedEventArgse)
{
xuanzhuan();
}
}
}
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对毛票票的支持。