Drawing Ellipses using WPF:
In this example we will show how to draw create a drawing similar to a human face using Ellipses. For this we first draw an Ellispse, and then draqw some smaller ellipses inside the first one, in place of eyes, nose and lips with different colors. 1.Go to File-->New Project-->Select WPF application and name it as WpfEllipse. 2.The new application will create window1.xaml and window1.xaml.cs files by default. 3.We can create our drawing by writing XML code in the xaml file, or by using writing c# code in the xaml.cs file, which is the code behind file. 4.In this example we are writing code in the .cs file. 5.We have to use the following namespace for drawing shapes. using System.Windows.Shapes;
6. We first create a canvas object as shown in line 26 and set its background color. 7. We draw our first Ellipse by creating an ellipse object as in line 31..Then we set the width and height of the ellipse as shown in lines 32 and 33. 8. Then we create a solid color brush object as in line 34 and assign it white color by setting ARGB(Alpha, Red, Green,Blue) colors. 9. Lines 37,38 and 39 select fill the ellipse object with the color brush object, set the stroke thickness and color with which the ellipse need to be drawn. 10. Lines 41 and 42 set the co-ordinates on the canvas, where the ellipse needs to be drawn. 11. Line 43 adds the Ellipse object to the Canvas object. 12. EYES,NOSE and Mouth/LIPS Ellipses are drawn in similar fashion, choosing different height-widths,colors,and canvas co-ordinates. 13. Line 111 fills the window with myCanvas object. 14. Line 112 sets the title of the window. 15. Finally Line 113 is to display the window. 16. When we run the above application the following ouput window is displayed: