WPF - SkewTransform

這篇測試一下SkewTransform的功能,做了一個"丟猴"的按鈕,有興趣的朋友可以跑程式測試看看

這篇測試一下SkewTransform的功能,做了一個"丟猴"的按鈕,有興趣的朋友可以跑程式測試看看

首先是XAML的定義,用Canvas當容器,像下面這樣

<Window    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
    x:Class="Window1"    Title="Window1" Height="346" Width="469" Name="Window1">
    <Window.Resources>
        <SolidColorBrush x:Key="BackColor">AliceBlue</SolidColorBrush>
        <SolidColorBrush x:Key="ForeColor">Red</SolidColorBrush>
    </Window.Resources>
    <Canvas Name="cv">
        <Button Name="btn1" Canvas.Left="10" Canvas.Top="10"
                Background="{StaticResource BackColor}" >
            SkewScale Test
        </Button>
    </Canvas>
</Window>

再來是測試的程式碼

 


Class Window1
    Dim st As New SkewTransform
    Dim myT As Threading.DispatcherTimer
    Dim R As New Random

    Dim tmpTop As Double = 0

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btn1.Click
        ''Timer相關設定    
        myT = New Threading.DispatcherTimer
        myT.Interval = New TimeSpan(0, 0, 0, 0, 100)
        AddHandler myT.Tick, AddressOf Timer_Tick
        myT.Start()
    End Sub

    Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
        If Canvas.GetTop(btn1) >= cv.ActualHeight Then
            myT.Stop()
        End If
        Randomize()
        st.AngleX = (0.5 - R.NextDouble) * 30
        st.AngleY = (0.5 - R.NextDouble) * 50
        System.Threading.Thread.Sleep(30)
        btn1.RenderTransform = st
        Canvas.SetLeft(btn1, R.NextDouble * 50)
        tmpTop = tmpTop + R.NextDouble * 10
        Canvas.SetTop(btn1, tmpTop)
    End Sub
End Class