Click here to Skip to main content
15,884,473 members
Articles / Programming Languages / C# 4.0

Reading Ultrabook Sensor Data with the Windows 8 Sensor API

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
6 Nov 2012CPOL2 min read 29.8K   1.1K   6  
A head start for App Innovation contestants
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace RedCell.App.Sensors
{
    /// <summary>
    /// A Metro-style group box.
    /// </summary>
    public class GroupBox : Panel
    {
        private Brush _back;
        private Brush _fore;

        /// <summary>
        /// Initializes a new instance of the <see cref="GroupBox" /> class.
        /// </summary>
        public GroupBox()
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GroupBox" /> class.
        /// </summary>
        /// <param name="container">The container.</param>
        public GroupBox(IContainer container)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private void Initialize()
        {
            // Default
            _back = new SolidBrush(Color.DarkGray); 
            _fore = new SolidBrush(Color.White);
        }

        /// <summary>
        /// Gets or sets the background color for the control.
        /// </summary>
        /// <value>The color of the back.</value>
        /// <returns>A <see cref="T:System.Drawing.Color" /> that represents the background color of the control. The default is the value of the <see cref="P:System.Windows.Forms.Control.DefaultBackColor" /> property.</returns>
        ///   <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   </PermissionSet>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [DefaultValue(typeof(Color), "DarkGray")]
        public override Color BackColor
        {
            get { return base.BackColor; }
            set { base.BackColor = value; }
        }

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.ForeColorChanged" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnForeColorChanged(System.EventArgs e)
        {
            base.OnForeColorChanged(e);
            if(_fore != null)
                _fore.Dispose();
            _fore = new SolidBrush(ForeColor);
        }

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.BackColorChanged" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnBackColorChanged(System.EventArgs e)
        {
            base.OnBackColorChanged(e);
            if (_back != null)
                _back.Dispose();
            _back = new SolidBrush(BackColor);
        }

        /// <summary>
        /// Raises the <see cref="E:PaintBackground" /> event.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs" /> instance containing the event data.</param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            e.Graphics.FillRectangle(_back, e.ClipRectangle);
        }

        /// <summary>
        /// Raises the <see cref="E:Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawString(Text, Font, _fore, 10, Height - 10 - Font.Size);
        }

        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.Control" /> and its child controls and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if(_fore != null)
                _fore.Dispose();
            _fore = null;
            if (_back != null)
                _back.Dispose();
            _back = null;
        }
    }
}

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
Engineer Robotic Assistance Devices / AITX
Canada Canada
Yvan Rodrigues has 30 years of experience in information systems and software development for the industry. He is Senior Concept Designer at Robotic Assistance Devices

He is a Certified Technician (C.Tech.), a professional designation granted by the Institute of Engineering Technology of Ontario (IETO).

Yvan draws on experience as owner of Red Cell Innovation Inc., Mabel's Labels Inc. as Manager of Systems and Development, the University of Waterloo as Information Systems Manager, and OTTO Motors as Senior Systems Engineer and Senior Concept Designer.

Yvan is currently focused on design of embedded systems.

Comments and Discussions