Advertisement
Guest User

WPF LED

a guest
Apr 22nd, 2011
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System.Windows.Media;
  2. using System.Windows.Shapes;
  3. using System.Windows;
  4.  
  5. namespace WPF_LED
  6. {
  7.     class LightEmittingDiode
  8.     {
  9.         public LightEmittingDiode(int Diameter, int PosX, int PosY, Color ColorOn)
  10.         {
  11.             _diameter = Diameter;
  12.             _posX = PosX;
  13.             _posY = PosY;
  14.             _ledColor = ColorOn;
  15.             _currentColor = Colors.LightGray;
  16.         }
  17.  
  18.         private int _diameter;
  19.         private int _posX;
  20.         private int _posY;
  21.         private Color _ledColor;
  22.         private Color _currentColor;
  23.         private bool _isOn = true;
  24.  
  25.         public int Diameter
  26.         {
  27.             get
  28.             {
  29.                 return _diameter;
  30.             }
  31.             set
  32.             {
  33.                 _diameter = value;
  34.             }
  35.         }
  36.         public int PosX
  37.         {
  38.             get
  39.             {
  40.                 return _posX;
  41.             }
  42.             set
  43.             {
  44.                 _posX = value;
  45.             }
  46.         }
  47.         public int PosY
  48.         {
  49.             get
  50.             {
  51.                 return _posY;
  52.             }
  53.             set
  54.             {
  55.                 _posY = value;
  56.             }
  57.         }
  58.         public Color LedColor
  59.         {
  60.             get
  61.             {
  62.                 return _ledColor;
  63.             }
  64.             set
  65.             {
  66.                 _ledColor = value;
  67.             }
  68.         }
  69.  
  70.         public Ellipse toEllipse()
  71.         {
  72.             Ellipse newLed = new Ellipse();
  73.             newLed.Width = Diameter;
  74.             newLed.Height = Diameter;
  75.             newLed.Margin = new Thickness(_posX, _posY, 0, 0);
  76.             newLed.Fill = new SolidColorBrush(_currentColor);
  77.  
  78.             return newLed;
  79.         }
  80.  
  81.         public void Toggle()
  82.         {
  83.             if (_isOn)
  84.             {
  85.                 _currentColor = _ledColor;
  86.                 _isOn = false;
  87.             }
  88.             else
  89.             {
  90.                 _currentColor = Colors.LightGray;
  91.                 _isOn = true;
  92.             }
  93.         }
  94.     }  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement