|
// Copyright (c) 2010, Peter Smith
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this list
// of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// Neither the name of the Author nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
namespace PS
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
/// <summary>
/// This class provides a basic interface to set up the Frequency and Speaker Location for incoming audio
/// </summary>
public partial class Radio : UserControl
{
#region Fields
private Color transmitterColor = Color.Red;
private Color notTransmittingColor;
private Color receiverColor = Color.DarkBlue;
private Color baseBackgroundShadowColor;
private Color receivingTransmissionIndicationColor = Color.Green;
private Color transmittingColor = Color.Maroon;
private Color receivingSignalColor = Color.Yellow;
private Color notReceivingSignalColor;
public enum RadioType { Transmitter, Receiver, Neither };
#endregion Fields
#region Constructors
/// <summary>
/// Constructor for a Radio Implementation.
/// </summary>
public Radio()
{
InitializeComponent();
}
#endregion Constructors
#region Events
/// <summary>
/// Event used by parent to indicate that the Radio control was pressed.
/// </summary>
[Category("Radio")]
[Description("Event used by parent to indicate that the Radio control was pressed.")]
public event EventHandler<EventArgs> RadioButtonPressed;
#endregion Events
#region Properties
/// <summary>
/// Background color used to indicate that the Radio is transmitting
/// </summary>
[Category("Radio")]
[Description("Background color used to indicate that the Radio is transmitting")]
public Color TransmittingColor
{
set { transmittingColor = value; }
get { return transmittingColor; }
}
/// <summary>
/// Font color used to indicate that the Radio is receiving data
/// </summary>
[Category("Radio")]
[Description("Font color used to indicate that the Radio is receiving data")]
public Color ReceivingSignalColor
{
set { receivingSignalColor = value; }
get { return receivingSignalColor; }
}
/// <summary>
/// Background shadow color used to indicate that the Radio is a Transmitter
/// </summary>
[Category("Radio")]
[Description("Background shadow color used to indicate that the Radio is a Transmitter")]
public Color TransmitterColor
{
set { transmitterColor = value; }
get { return transmitterColor; }
}
/// <summary>
/// Background shadow color used to indicate that the Radio is a Transmitter
/// </summary>
[Category("Radio")]
[Description("Background shadow color used to indicate that the Radio is a Transmitter")]
public Color ReceiverColor
{
set { receiverColor = value; }
get { return receiverColor; }
}
/// <summary>
/// Background shadow color used to indicate that the Radio is not a Transmitter nor a Receiver
/// </summary>
[Category("Radio")]
[Description("Background shadow color used to indicate that the Radio is not a Transmitter nor a Receiver")]
public Color BaseBackgroundShadowColor
{
set
{
this.BackColor = value;
baseBackgroundShadowColor = value;
}
get { return baseBackgroundShadowColor; }
}
/// <summary>
/// Displays the Frequency on the Radio Control
/// </summary>
[Category("Radio")]
[Description("Displays the Frequency on the Radio Control")]
public override string Text
{
get
{
return label_Radio.Text;
}
set
{
label_Radio.Text = value;
}
}
[Browsable(false)] //Hide this option from users
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
}
}
#endregion Properties
#region Methods
/// <summary>
/// Changes the background color of the Radio set to indicate not transmitting
/// </summary>
public void RadioStoppedTransmitting()
{
this.label_Radio.BackColor = notTransmittingColor;
}
/// <summary>
/// Changes the background color of the Radio set to indicate transmitting
/// </summary>
public void RadioTransmitting()
{
this.label_Radio.BackColor = TransmittingColor;
}
public void ChangeRadioReceivingSignal(bool isReceiving)
{
if (isReceiving == true)
this.label_Radio.ForeColor = receivingSignalColor;
else
this.label_Radio.ForeColor = notReceivingSignalColor;
}
/// <summary>
/// Set the background shadow color based upon the type of Radio
/// </summary>
/// <param name="radioType">Radio Type</param>
public void SetRadioShadowType(RadioType radioType)
{
switch (radioType)
{
case RadioType.Transmitter:
this.BackColor = TransmitterColor;
break;
case RadioType.Receiver:
this.BackColor = ReceiverColor;
break;
case RadioType.Neither:
this.BackColor = BaseBackgroundShadowColor;
break;
default:
break;
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected override void OnLayout(LayoutEventArgs e)
{
base.OnLayout(e);
notTransmittingColor = this.label_Radio.BackColor;
BaseBackgroundShadowColor = this.BackColor;
notReceivingSignalColor = this.label_Radio.ForeColor;
}
private void label_Radio_Click(object sender, EventArgs e)
{
RadioButtonPressedEvent();
}
private void RadioButtonPressedEvent()
{
EventHandler<EventArgs> temp = RadioButtonPressed;
if (temp != null)
temp(this, EventArgs.Empty);
}
#endregion Methods
}
}
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.