模拟螺旋桨(Simulate a propeller)

编程入门 行业动态 更新时间:2024-10-20 08:01:18
模拟螺旋桨(Simulate a propeller)

我有这个代码在画布上显示一个矩形:

XAML:

<Window x:Class="rotateRect.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:rotateRect" mc:Ignorable="d" Title="MainWindow" Height="402.027" Width="600.676"> <Grid> <Canvas Name="my_c" HorizontalAlignment="Left" Height="24" Margin="160,149,0,0" VerticalAlignment="Top" Width="177" RenderTransformOrigin="0.5,0.5"> <Canvas.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="-68.962"/> <TranslateTransform/> </TransformGroup> </Canvas.RenderTransform> </Canvas> </Grid>

我可以使用“RenderTransform”将其转换为XAML。 但我想在c#中实现这种旋转并创建一个“螺旋桨”。 我试图为画布找到有关“RotateTransform”的信息。 你是我的c#代码:

C# :

using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace rotateRect { public partial class MainWindow : Window { Rectangle my_r = new Rectangle(); public MainWindow() { InitializeComponent(); initializeRect(my_r, my_c); } private void initializeRect(Rectangle r, Canvas c) { // rectangle r.Width = 10; r.Height = 50; // rectangle Color r.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255)); // canvas c.Children.Add(r); c.Width = 10; c.Height = 50; } } }

我为一个位图对象找到了一个“RotateTransform”的例子,但我没有为画布找到任何东西。 C#,旋转图形?

可以将RotateTransform应用于c#中的画布吗?

I have this code that display a rectangle on a canvas :

XAML :

<Window x:Class="rotateRect.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:rotateRect" mc:Ignorable="d" Title="MainWindow" Height="402.027" Width="600.676"> <Grid> <Canvas Name="my_c" HorizontalAlignment="Left" Height="24" Margin="160,149,0,0" VerticalAlignment="Top" Width="177" RenderTransformOrigin="0.5,0.5"> <Canvas.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="-68.962"/> <TranslateTransform/> </TransformGroup> </Canvas.RenderTransform> </Canvas> </Grid>

I can turn it in XAML with "RenderTransform". But i wanted to implement this rotation in c# and create a "propeller". I tried to find information about "RotateTransform" for a canvas. Thys is my c# code :

C# :

using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace rotateRect { public partial class MainWindow : Window { Rectangle my_r = new Rectangle(); public MainWindow() { InitializeComponent(); initializeRect(my_r, my_c); } private void initializeRect(Rectangle r, Canvas c) { // rectangle r.Width = 10; r.Height = 50; // rectangle Color r.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255)); // canvas c.Children.Add(r); c.Width = 10; c.Height = 50; } } }

I found an exemple of "RotateTransform" for a bitmap object but i hadn't find anything for a canvas. C#, rotating Graphics?

It's possible to apply a RotateTransform to a canvas in c#?

最满意答案

修改initializeRect方法

private void initializeRect(Rectangle r, Canvas c) { // rectangle r.Width = 10; r.Height = 50; // rectangle Color r.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255)); // canvas c.Children.Add(r); c.Width = 10; c.Height = 50; RotateTransform rt = new RotateTransform(); rt.Angle=-68.962; c.RenderTransform = rt; }

modify your initializeRect methode

private void initializeRect(Rectangle r, Canvas c) { // rectangle r.Width = 10; r.Height = 50; // rectangle Color r.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255)); // canvas c.Children.Add(r); c.Width = 10; c.Height = 50; RotateTransform rt = new RotateTransform(); rt.Angle=-68.962; c.RenderTransform = rt; }

更多推荐

本文发布于:2023-07-04 17:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027000.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:螺旋桨   Simulate   propeller

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!