重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

c#实现图片的平移和旋转示例代码

前言

专注于为中小企业提供网站建设、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业宁国免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

本文主要给大家分享了关于利用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
{
 /// 
 /// MainWindow.xaml 的交互逻辑
 /// 
 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();
  }
 }
}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对创新互联的支持。


网站题目:c#实现图片的平移和旋转示例代码
URL分享:http://cqcxhl.cn/article/pesdjp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP