Click here to Skip to main content
15,881,709 members
Articles / Desktop Programming / WPF

Full Screen WPF Application with a Low-Level Keyboard Hook

Rate me:
Please Sign up or sign in to vote.
4.75/5 (29 votes)
26 Nov 2008CPOL7 min read 120.9K   3.1K   48  
This application displays shapes of random sizes and colors. It's perfect for babies and toddlers who love to sit and press away at the keyboard.
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace ShapeShow.Library
{
    /// <summary>
    /// Represents a square or rectangle.
    /// </summary>
    class Square : IShape
    {
        #region Private Members

        PointCollection _points;
        Polygon _primitive;
        TranslateTransform _translateTransform;

        #endregion

        #region IShape Members

        public PointCollection Points
        {
            get { return _points; }
        }

        public Double Height
        {
            get { return _primitive.Height; }
            set { _primitive.Height = value; }
        }

        public Double Width
        {
            get { return _primitive.Width; }
            set { _primitive.Width = value; }
        }

        public Double Top
        {
            get { return _translateTransform.Y; }
            set { _translateTransform.Y = value; }
        }

        public Double Left
        {
            get { return _translateTransform.X; }
            set { _translateTransform.X = value; }
        }

        public Brush FillBrush
        {
            get { return _primitive.Fill; }
            set { _primitive.Fill = value; }
        }

        public Double OutlineWidth
        {
            get { return _primitive.StrokeThickness; }
            set { _primitive.StrokeThickness = value; }
        }

        public Brush OutlineBrush
        {

            get { return _primitive.Stroke; }
            set { _primitive.Stroke = value; }
        }

        public UIElement UIElement
        {
            get { return _primitive; }
        }

        #endregion

        #region Constructors

        public Square()
        {
            _points = new PointCollection(4);
            _points.Add(new Point(0, 0));
            _points.Add(new Point(1, 0));
            _points.Add(new Point(1, 1));
            _points.Add(new Point(0, 1));

            _translateTransform = new TranslateTransform(0, 0);

            _primitive = new Polygon();
            _primitive.Points = _points;
            _primitive.RenderTransform = _translateTransform;
            _primitive.Stretch = Stretch.Fill;
            _primitive.Stroke = Brushes.Black;
            _primitive.StrokeThickness = 2;
        }

        public Square(Double height, Double width) : this()
        {
            Height = height;
            Width = width;
        }

        public Square(Double height, Double width, Double top, Double left) : this(height, width)
        {
            Top = top;
            Left = left;
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
Barry Dorman is a software engineer from the Birmingham, AL area. His primary focus is ASP.NET. Barry graduated with a BS in Electrical Engineering from The University of Alabama at Birmingham in 2006. Since then, he has kept himself busy working in the healthcare industry.

Comments and Discussions