using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SilverlightNaited { public partial class KujunditeJoonistus2 : UserControl { LinkedList kujundid = new LinkedList(); public KujunditeJoonistus2() { InitializeComponent(); kujundid.AddLast(joonista(ala1, new Rectangle(), 20, 50, 40, 30, Colors.Green)); kujundid.AddLast(joonista(ala1, new Ellipse(), 70, 50, 40, 30, Colors.Yellow)); kujundid.AddLast(joon(ala1, 120, 50, 160, 80, Colors.Blue)); foreach(Shape kujund in kujundid){ kujund.MouseEnter += new MouseEventHandler(hiirSisenes); kujund.MouseLeave+=new MouseEventHandler(hiirLahkus); } } Shape joon(Canvas ala, double x1, double y1, double x2, double y2, Color varv) { Line j = new Line(); j.X1 = x1; j.Y1 = y1; j.X2 = x2; j.Y2 = y2; j.Stroke = new SolidColorBrush(varv); ala.Children.Add(j); return j; } void hiirSisenes(object sender, MouseEventArgs e) { Shape kujund = sender as Shape; kujund.Opacity = kujund.Opacity / 2; } void hiirLahkus(object sender, MouseEventArgs e) { Shape kujund = sender as Shape; kujund.Opacity = kujund.Opacity * 2; } Shape joonista(Canvas ala, Shape kujund, double vasak, double yla, double laius, double korgus, Color varv) { Canvas.SetLeft(kujund, vasak); Canvas.SetTop(kujund, yla); kujund.Width = laius; kujund.Height = korgus; kujund.Fill = new SolidColorBrush(varv); ala.Children.Add(kujund); return kujund; } } }