ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • WPF Basic 2D Graphics Shapes
    .NET/WPF 2D 2013. 6. 19. 00:11
    반응형






    <Window x:Class="WpfApplication6.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         Title="Basic 2D Graphics Shapes" Height="800" Width="830"> <Grid>     <Line X1="30" Y1="30"               X2 ="180" Y2="30"               Stroke="Blue"               StrokeThickness="2"/>     <Line X1="30" Y1="50" X2 ="250" Y2="50"   Stroke="Blue" StrokeThickness="2"  StrokeDashArray="5,3" />     <Line X1="30" Y1="70" X2 ="250" Y2="70"   Stroke="Blue" StrokeThickness="2"  StrokeDashArray="5,1,3,2" />

    <Line X1="30" Y1="90" X2 ="250" Y2="90"   Stroke="Blue" StrokeThickness="2"  StrokeDashArray="5,1,3" /> <StackPanel Margin="0,100,0,0" Orientation="Horizontal"> <StackPanel> <TextBlock Text="RadiusX = 0, RadiusY = 0:"                         Margin="10 10 10 5"/> <Rectangle Width="150" Height="70"                         Fill="LightGray" Stroke="Black"/> <TextBlock Text="RadiusX = 20, RadiusY = 10:"                         Margin="10 10 10 5"/> <Rectangle Width="150" Height="70"                          RadiusX="20" RadiusY="10"                          Fill="LightGray" Stroke="Black"/> <TextBlock Text="RadiusX = 75, RadiusY = 35:"                         Margin="10 10 10 5"/> <Rectangle Width="150" Height="70"                          RadiusX="75" RadiusY="35"                          Fill="LightGray" Stroke="Black"/> <TextBlock Text="Ellipse:" Margin="10 10 10 5"/> <Ellipse Width="150" Height="70"                        Fill="LightGray" Stroke="Black"/> <TextBlock Text="Circle:" Margin="10 10 10 5"/> <Ellipse Width="100" Height="100"                        Fill="LightGray" Stroke="Black"/> </StackPanel> <StackPanel  Margin="10,0,0,0" 

    HorizontalAlignment="Stretch" VerticalAlignment="Top" Width="Auto" >

    <Grid ShowGridLines="True"  Height="400" Width="380" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"> <Grid.RowDefinitions>     <RowDefinition Height="Auto"/>     <RowDefinition />     <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions>     <ColumnDefinition Width="Auto"/>     <ColumnDefinition />     <ColumnDefinition />     <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Grid.Row="1" Text="Rectagle" Margin="5"/> <TextBlock Grid.Column="0" Grid.Row="2" Text="Ellipse" Margin="5"/> <TextBlock Grid.Column="1" Grid.Row="0" Text="Fill" 

    TextAlignment="Center" Margin="5"/>

    <TextBlock Grid.Column="2" Grid.Row="0" Text="Uniform"                     TextAlignment="Center" Margin="5"/> <TextBlock Grid.Column="3" Grid.Row="0"                     Text="UniformToFill" TextAlignment="Center"                     Margin="5"/> <Rectangle Grid.Column="1" Grid.Row="1"                      Fill="LightGray" Stroke="Black"                      Stretch="Fill" Margin="5"/> <Rectangle Grid.Column="2" Grid.Row="1"                     Fill="LightGray" Stroke="Black"                      Stretch="Uniform" Margin="5"/> <Rectangle Grid.Column="3" Grid.Row="1"                     Fill="LightGray" Stroke="Black"                     Stretch="UniformToFill" Margin="5"/> <Ellipse Grid.Column="1" Grid.Row="2" Fill="LightGray"  Stroke="Black" Stretch="Fill" Margin="5"/> <Ellipse Grid.Column="2" Grid.Row="2" Fill="LightGray"  Stroke="Black" Stretch="Uniform" Margin="5"/> <Ellipse Grid.Column="3" Grid.Row="2" Fill="LightGray"  Stroke="Black" Stretch="UniformToFill"  Margin="5"/>

    </Grid> <StackPanel> <TextBlock Text="Polyline:"/> <Polyline Stroke="Black" StrokeThickness="3"   Points="0 70,60 10,110 60,160 10,210 70"/> <TextBlock Text="Closed polyline:"   Margin="0 10 0 0"/> <Polyline Stroke="Black" StrokeThickness="3"   Points="0 70,60 10,110 60,160 10,210 70, 0 70"/> <TextBlock Text="Sine curve: codebehind" Margin="0 10 0 0"/> <Polyline Name="polyline1" Stroke="Red" StrokeThickness="2"/> </StackPanel>

    </StackPanel> <StackPanel Margin="5,0,0,0">     <TextBlock Text="Polygon:"/>     <Polygon Stroke="Black" StrokeThickness="3" Fill="LightGray"                       Points="0 70,60 10,110 60,160 10,210 70"/>     <TextBlock Text="Filled sine curve: codebehind" Margin="0 10 0 0"/>     <Polygon Name="polygon1" Stroke="Red" 

    StrokeThickness="2" Fill="LightCoral"/>

    <TextBlock Text="FileRule = EvenOdd:" Margin="0 0 0 5"/> <Polygon Stroke="Black" Fill="LightGray" FillRule="EvenOdd"                        Points="0 0,0 150,100 150,100 50,                               50 50,50 100,150 100,150 0"/> <TextBlock Text="FileRule = NonZero:" Margin="0 10 0 5"/> <Polygon Stroke="Black" Fill="LightGray" FillRule="Nonzero"                        Points="0 0,0 150,100 150,100 100,50 100,                           50 50,100 50,100 100,150 100,150 0"/>

    </StackPanel>

    </StackPanel>

    </Grid> </Window>




    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
     
                for (int i = 0i < 70i++)
                {
                    double x = i * Math.PI;
                    double y = 40 + 30 * Math.Sin(x / 10);
                    polyline1.Points.Add(new Point(xy));
                }
     
     
                for (int i = 0i < 71i++)
                {
                    double x = i * Math.PI;
                    double y = 40 + 30 * Math.Sin(x / 10);
                    polygon1.Points.Add(new Point(xy));
                } 
            }
        }




    reference : Practical WPF Graphics Programming
























    반응형

    댓글

Designed by Tistory.