c#wpf 2d graphics - 寻找教程/示例

时间:2010-01-02 19:49:56

标签: c# wpf graphics 2d

请你指点一个好的C#教程,使用WPF在Canvas上绘制像Ellipse和Rectangle(继承自Shape)的2D图形? 我以后也有兴趣点击形状并识别被点击的形状,以及在画布上拖放形状。 谢谢!


感谢您的链接。 您能否告诉我,我应该在Visual Studio中启动哪个项目来编译和运行此程序(取自Shapes and Basic Drawing in WPF):

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SDKSample
{
    public partial class SetBackgroundColorOfShapeExample : Page
    {
        public SetBackgroundColorOfShapeExample()
        {
            // Create a StackPanel to contain the shape.
            StackPanel myStackPanel = new StackPanel();

            // Create a red Ellipse.
            Ellipse myEllipse = new Ellipse();

            // Create a SolidColorBrush with a red color to fill the 
            // Ellipse with.
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();

            // Describes the brush's color using RGB values. 
            // Each value has a range of 0-255.
            mySolidColorBrush.Color = Color.FromArgb(255, 255, 255, 0);
            myEllipse.Fill = mySolidColorBrush;
            myEllipse.StrokeThickness = 2;
            myEllipse.Stroke = Brushes.Black;

            // Set the width and height of the Ellipse.
            myEllipse.Width = 200;
            myEllipse.Height = 100;

            // Add the Ellipse to the StackPanel.
            myStackPanel.Children.Add(myEllipse);

            this.Content = myStackPanel;
        }

    }
}

1 个答案:

答案 0 :(得分:3)

MSDN非常了解Shapes and Basic Drawing in WPF

有关处理的信息,请点击形状,请参阅Hit Testing in the Visual Layer