如何在 C# 中绘制旋转椭圆



旋转椭圆表示 - 不平行于屏幕的轴。可以用WinForms画吗?如果不可能,如何使用 WPF 绘制它?如果我必须使用 WPF,我不想在 xaml 中定义它,因为我想像 CAD 应用程序一样绘制数千个实体。

您可以使用我之前使用的以下 xaml 旋转日食。

<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Storyboard x:Key="Storyboard1">
            <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="ball">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="360"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
        </EventTrigger>
    </Window.Triggers>
    <Grid>
         <Canvas Width="700" Height="500">
        <Grid Height="462" Width="700" Canvas.Top="-18">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="700*" />
                <ColumnDefinition Width="0*" />
                <ColumnDefinition Width="0*" />
            </Grid.ColumnDefinitions>
            <Ellipse Margin="108,88,0,0" Name="ball" Stroke="Black" Height="129"                                                             
                  VerticalAlignment="Top" Stretch="UniformToFill" HorizontalAlignment="Left"            
                   Width="128" RenderTransformOrigin="0.5,0.5">
                <Ellipse.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform />
                        <TranslateTransform/>
                    </TransformGroup>
                </Ellipse.RenderTransform>
                <Ellipse.Fill>
                    <ImageBrush ImageSource="C:UsersA TECHDesktopproject2.jpg"/>
                </Ellipse.Fill>
                <Ellipse.BitmapEffect>
                    <BevelBitmapEffect BevelWidth="1" />
                </Ellipse.BitmapEffect>
                <Ellipse.BitmapEffectInput>
                    <BitmapEffectInput />
                </Ellipse.BitmapEffectInput>
            </Ellipse>
            <Rectangle Height="13" Margin="200,390,0,0" Name="pad" Stroke="Black"  
             VerticalAlignment="Bottom" Fill="Black" HorizontalAlignment="Left" Width="100" />
        </Grid>
    </Canvas>
    </Grid>
</Window>

最新更新