C/C++培训
达内IT学院
400-996-5531
本文主要给大家分享了关于利用c#实现图片的平移和旋转的相关内容,分享出来供大家参考学习,话不多说了,来一起看看详细的介绍吧,上代码!
方法如下:
1、新建文件夹,添加一个图片
2 、添加控件 两个button控件 一个image控件 一个Canvas控件
3 、代码实现如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication16
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = -100;
Storyboard board = new Storyboard();
Storyboard .SetTarget(da,image);
Storyboard.SetTargetProperty(da,new PropertyPath(Canvas.LeftProperty));
board.Children.Add(da);
board.Begin();
}
private void xuanzhuan()
{
RotateTransform totate = new RotateTransform();
image.RenderTransform = totate;
image.RenderTransformOrigin = new Point(0.5, 0.5);
DoubleAnimation da = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromMilliseconds(500)));
Storyboard board = new Storyboard();
Storyboard.SetTarget(da, image);
Storyboard.SetTargetProperty(da,new PropertyPath("RenderTransform.Angle"));
da.RepeatBehavior = RepeatBehavior.Forever;
da.Completed += Da_Completed;
board.Children.Add(da);
board.Begin();
}
private void Da_Completed(object sender, EventArgs e)
{
}
private void button1_Click(object sender, RoutedEventArgs e)
{
xuanzhuan();
}
}
}
免责声明:整理文章为传播相关技术,版权归原作者所有,如有侵权,请联系删除
填写下面表单即可预约申请免费试听!怕钱不够?可就业挣钱后再付学费! 怕学不会?助教全程陪读,随时解惑!担心就业?一地学习,可全国推荐就业!
Copyright © 京ICP备08000853号-56 京公网安备 11010802029508号 达内时代科技集团有限公司 版权所有
Tedu.cn All Rights Reserved