c#實(shí)現(xiàn)圖片的平移和旋轉(zhuǎn)示例代碼
前言
本文主要給大家分享了關(guān)于利用c#實(shí)現(xiàn)圖片的平移和旋轉(zhuǎn)的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹吧
方法如下
1新建文件夾,添加一個(gè)圖片
2 添加控件 兩個(gè)button控件 一個(gè)image控件 一個(gè)Canvas控件
3 代碼實(shí)現(xiàn)
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();
}
}
}
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
C# winform實(shí)現(xiàn)自動(dòng)更新
這篇文章主要為大家詳細(xì)介紹了C# winform實(shí)現(xiàn)自動(dòng)更新的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-10-10
C#實(shí)現(xiàn)自定義線程池實(shí)例代碼
這篇文章介紹了C#實(shí)現(xiàn)自定義線程池的實(shí)例代碼,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-07-07
ASP.NET總結(jié)C#中7種獲取當(dāng)前路徑的方法
本文主要介紹了7種獲取當(dāng)前路徑的方法,并做了代碼演示,分享給大家,感興趣的朋友可以參考一下。2016-03-03
unity實(shí)現(xiàn)貼圖矩陣運(yùn)算(旋轉(zhuǎn)平移縮放)
這篇文章主要為大家詳細(xì)介紹了unity實(shí)現(xiàn)貼圖矩陣運(yùn)算,旋轉(zhuǎn)平移縮放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07
讓C# Excel導(dǎo)入導(dǎo)出 支持不同版本Office
讓C# Excel導(dǎo)入導(dǎo)出,支持不同版本的Office,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
C#使用UdpClient類進(jìn)行簡單通信的實(shí)例
本文主要介紹了C#使用UdpClient類進(jìn)行簡單通信的實(shí)例,具有很好的參考價(jià)值,需要的朋友可以看下2016-12-12
WPF實(shí)現(xiàn)帶模糊搜索的DataGrid的示例代碼
這篇文章主要為大家詳細(xì)介紹了WPF如何實(shí)現(xiàn)帶模糊搜索的DataGrid,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下2023-02-02

