MainWindow.xaml.csの全コード
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfGraphics
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MenuItem2_Click(object sender, RoutedEventArgs e)
{
Grid1.Children.Clear();
Line myLine = new Line();
myLine.Stroke = Brushes.LightSteelBlue;
myLine.X1 = 20;
myLine.X2 = 150;
myLine.Y1 = 30;
myLine.Y2 = 250;
myLine.HorizontalAlignment = HorizontalAlignment.Left;
myLine.VerticalAlignment = VerticalAlignment.Top;
myLine.StrokeThickness = 2;
Grid1.Children.Add(myLine);
Path myPath2 = new Path();
myPath2.Stroke = Brushes.DarkViolet;
myPath2.StrokeThickness = 6;
LineGeometry myGeometry2 = new LineGeometry();
myGeometry2.StartPoint = new System.Windows.Point(30, 50);
myGeometry2.EndPoint = new System.Windows.Point(250, 250);
myPath2.Data = myGeometry2;
Grid1.Children.Add(myPath2);
}
private void MenuItem3_Click(object sender, RoutedEventArgs e)
{
RotateTransform an = new RotateTransform();
an.CenterX = 100;
an.CenterY = 100;
an.Angle = 45;
Grid1.Children.Clear();
Rectangle myRectangle = new Rectangle();
Thickness myThickness = new Thickness();
myThickness.Left = 120;
myThickness.Top = 120;
myThickness.Right = 0;
myThickness.Bottom = 0;
myRectangle.HorizontalAlignment =HorizontalAlignment.Left;
myRectangle.VerticalAlignment = VerticalAlignment.Top;
myRectangle.Margin = myThickness;
myRectangle.Stroke = Brushes.SaddleBrown;
myRectangle.Width = 100;
myRectangle.Height = 60;
myRectangle.Fill = Brushes.SeaGreen;
myRectangle.RenderTransform = an;
Grid1.Children.Add(myRectangle);
Path myPath3 = new Path();
myPath3.Stroke = Brushes.Red;
myPath3.Fill = Brushes.RoyalBlue;
myPath3.StrokeThickness = 4;
RectangleGeometry myGeometry3 = new RectangleGeometry();
myGeometry3.Rect = new System.Windows.Rect(150, 200, 70, 100);
myPath3.Data = myGeometry3;
myPath3.RenderTransform = an;
Grid1.Children.Add(myPath3);
}
private void MenuItem4_Click(object sender, RoutedEventArgs e)
{
RotateTransform an = new RotateTransform();
an.CenterX = 100;
an.CenterY = 100;
an.Angle = 45;
Grid1.Children.Clear();
Ellipse myEllipse = new Ellipse();
Thickness myThickness2 = new Thickness();
myThickness2.Left = 20;
myThickness2.Top = 120;
myThickness2.Right = 0;
myThickness2.Bottom = 0;
myEllipse.HorizontalAlignment =HorizontalAlignment.Left;
myEllipse.VerticalAlignment = VerticalAlignment.Top;
myEllipse.Margin = myThickness2;
myEllipse.Stroke = Brushes.Aquamarine;
myEllipse.Width = 100;
myEllipse.Height = 60;
myEllipse.Fill = Brushes.Coral;
myEllipse.RenderTransform = an;
Grid1.Children.Add(myEllipse);
Path myPath4 = new Path();
myPath4.Stroke = Brushes.Black;
myPath4.Fill = Brushes.MediumSlateBlue;
myPath4.StrokeThickness = 2;
EllipseGeometry myGeometry4 = new EllipseGeometry();
myGeometry4.Center = new System.Windows.Point(250, 50);
myGeometry4.RadiusX = 25;
myGeometry4.RadiusY = 50;
myPath4.Data = myGeometry4;
myPath4.RenderTransform = an;
Grid1.Children.Add(myPath4);
}
private void MenuItem5_Click(object sender, RoutedEventArgs e)
{
Grid1.Children.Clear();
Image myImage = new Image();
var imageUri = new Uri("http://homepage3.nifty.com/skomo/f30/99-3-20b.jpg");
myImage.Source = new BitmapImage(imageUri);
myImage.Width = 200;
myImage.Height = 200;
myImage.HorizontalAlignment =HorizontalAlignment.Center;
myImage.VerticalAlignment = VerticalAlignment.Center;
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
myEllipseGeometry.Center = new Point(100, 100);
myEllipseGeometry.RadiusX = 90;
myEllipseGeometry.RadiusY = 100;
myImage.Clip = myEllipseGeometry;
RotateTransform an = new RotateTransform();
an.CenterX = 100;
an.CenterY = 100;
an.Angle = 45;
myImage.RenderTransform = an;
Grid1.Children.Add(myImage);
}
private void MenuItem6_Click(object sender, RoutedEventArgs e)
{
Grid1.Children.Clear();
Path myPath5 = new Path();
myPath5.Stroke = Brushes.Black;
myPath5.Fill = Brushes.MediumSlateBlue;
myPath5.StrokeThickness = 2;
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(10, 30);
myPathFigure.Segments.Add(new BezierSegment(new Point(100,0), new Point(200, 200), new Point(300, 100),true));
myPathFigure.Segments.Add(new LineSegment(new Point(400, 100), true));
myPathFigure.Segments.Add(new ArcSegment(new Point(200, 100), new Size(50, 50), 45, true, SweepDirection.Clockwise, true));
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures.Add(myPathFigure);
myPath5.Data = myPathGeometry;
RotateTransform an = new RotateTransform();
an.CenterX = 100;
an.CenterY = 100;
an.Angle = 45;
myPath5.RenderTransform = an;
Grid1.Children.Add(myPath5);
}
}
}