John Ortiz Ordoñez


John Ortiz Ordoñez MVP .NET
(2015, 2016)

Ingeniero en Computación - Universidad de los Andes (Colombia)
Ingeniero de Sistemas - Universidad Cooperativa de Colombia
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Ch02
{
///<summary>
/// Clase que forma la interfaz básica para los controles de un radio
/// bajo un formulario.
///</summary>
public partial class RadioGUI : Form
{
System.ComponentModel.Container components = null;
///<summary>
/// Constructor de sin-argumentos
///</summary>
public RadioGUI()
{
InitializeComponents();
}
///<summary>
/// Uso del patrón Disposable esencial para la liberación
/// de recursos del sistema.
///</summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region INITILIZE_CODE
///<summary>
/// Inicializa las propiedades básica del formulario e invoca los métodos de creación
/// de controles integrales de la interfaz del radio.
///</summary>
protected void InitializeComponents()
{
// Establece varias de las propiedades del formulario.
this.Font = new Font("Segoe UI", 9);
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "frmRadioGui";
this.Size = new Size(427, 194);
this.Text = "Radio";
CreatePresetStationsButtons();
CreateSpeakerOptions();
CreatePowerOnOffButton();
CreateVolumeControl();
CreateTunningControls();
CreateJukebox();
}
#endregion
#region CUSTOM_CODE
///<summary>
/// Crea los botones de pre-sintonía.
///</summary>
private void CreatePresetStationsButtons()
{
GroupBox gbxPresetStations = new GroupBox();
gbxPresetStations.Location = new Point(11,13);
gbxPresetStations.Name = "gbxPresetStations";
gbxPresetStations.Size = new Size(180, 55);
gbxPresetStations.Text = "Pre-set Stations";
// Adds the pre-set stations buttons
Button btnPresetStationNo1 = new Button();
btnPresetStationNo1.Location = new Point(6, 21);
btnPresetStationNo1.Name = "btnPresetStationNo1";
btnPresetStationNo1.Size = new Size(23, 23);
btnPresetStationNo1.Text = "1";
gbxPresetStations.Controls.Add(btnPresetStationNo1);
Button btnPresetStationNo2 = new Button();
btnPresetStationNo2.Location = new Point(35, 21);
btnPresetStationNo2.Name = "btnPresetStationNo2";
btnPresetStationNo2.Size = new Size(23, 23);
btnPresetStationNo2.Text = "2";
gbxPresetStations.Controls.Add(btnPresetStationNo2);
Button btnPresetStationNo3 = new Button();
btnPresetStationNo3.Location = new Point(64, 21);
btnPresetStationNo3.Name = "btnPresetStationNo3";
btnPresetStationNo3.Size = new Size(23, 23);
btnPresetStationNo3.Text = "3";
gbxPresetStations.Controls.Add(btnPresetStationNo3);
Button btnPresetStationNo4 = new Button();
btnPresetStationNo4.Location = new Point(93, 21);
btnPresetStationNo4.Name = "btnPresetStationNo4";
btnPresetStationNo4.Size = new Size(23, 23);
btnPresetStationNo4.Text = "4";
gbxPresetStations.Controls.Add(btnPresetStationNo4);
Button btnPresetStationNo5 = new Button();
btnPresetStationNo5.Location = new Point(122, 21);
btnPresetStationNo5.Name = "btnPresetStationNo2";
btnPresetStationNo5.Size = new Size(23, 23);
btnPresetStationNo5.Text = "5";
gbxPresetStations.Controls.Add(btnPresetStationNo5);
Button btnPresetStationNo6 = new Button();
btnPresetStationNo6.Location = new Point(151, 21);
btnPresetStationNo6.Name = "btnPresetStationNo6";
btnPresetStationNo6.Size = new Size(23, 23);
btnPresetStationNo6.Text = "6";
gbxPresetStations.Controls.Add(btnPresetStationNo6);
this.Controls.Add(gbxPresetStations);
}
///<summary>
/// Crea los controles para controlar los parlantes frontales y anteriores de la interfaz del radio.
///</summary>
private void CreateSpeakerOptions()
{
// Crea el GroupBox para las opciones de los parlantes.
GroupBox gbxSpeakers = new GroupBox();
gbxSpeakers.Location = new Point(198, 13);
gbxSpeakers.Name = "gbxSpeakers";
gbxSpeakers.Size = new Size(120, 55);
gbxSpeakers.Text = "Speakers";
CheckBox ckxRear = new CheckBox();
ckxRear.AutoSize = true;
ckxRear.Location = new Point(6, 21);
ckxRear.Name = "ckxRear";
ckxRear.Text = "Rear";
gbxSpeakers.Controls.Add(ckxRear);
CheckBox ckxFront = new CheckBox();
ckxFront.AutoSize = true;
ckxFront.Location = new Point(57, 21);
ckxFront.Name = "ckxFront";
ckxFront.Text = "Front";
gbxSpeakers.Controls.Add(ckxFront);
this.Controls.Add(gbxSpeakers);
}
///<summary>
/// Crea el botón de apagado y encendido de la interfaz del radio.
///</summary>
private void CreatePowerOnOffButton()
{
Button btnPowerOnOff = new Button();
btnPowerOnOff.Location = new Point(325, 13);
btnPowerOnOff.Name = "btnPowerOnOff";
btnPowerOnOff.Size = new Size(75, 55);
btnPowerOnOff.Text = "Power On/Off";
this.Controls.Add(btnPowerOnOff);
}
///<summary>
/// Crea el manejador de silencio y nivel de volumen de la interfaz del radio.
///</summary>
private void CreateVolumeControl()
{
GroupBox gbxVolumeControl = new GroupBox();
gbxVolumeControl.Location = new Point(11, 83);
gbxVolumeControl.Name = "gbxVolumeControl";
gbxVolumeControl.Size = new Size(180, 70);
gbxVolumeControl.Text = "Volume Control";
// Crea el control de activar o desactivar el sonido
CheckBox ckxMute = new CheckBox();
ckxMute.AutoSize = true;
ckxMute.Location = new Point(6, 21);
ckxMute.Name = "ckxMute";
ckxMute.Text = "Mute";
gbxVolumeControl.Controls.Add(ckxMute);
// Crea la barra de nivel de volumen del radio
TrackBar tkbVolume = new TrackBar();
tkbVolume.Location = new Point(67, 21);
tkbVolume.Name = "tkbVolume";
gbxVolumeControl.Controls.Add(tkbVolume);
this.Controls.Add(gbxVolumeControl);
}
///<summary>
/// Crea los controles para alternar entre FM y AM, y el visualizador de frecuencia sintonizada.
///</summary>
private void CreateTunningControls()
{
GroupBox gbxTunning = new GroupBox();
gbxTunning.Location = new Point(198, 83);
gbxTunning.Name = "gbxTunning";
gbxTunning.Size = new Size(120, 70);
gbxTunning.Text = "Tunning";
Label lblTunned = new Label();
lblTunned.AutoSize = false;
lblTunned.BackColor = Color.Black;
lblTunned.Font = new Font( "Segoe UI", 12);
lblTunned.ForeColor = Color.Silver;
lblTunned.Location = new Point(6, 21);
lblTunned.Name = "lblTunned";
lblTunned.Size = new Size(50, 44);
lblTunned.Text = "92.9";
lblTunned.TextAlign = ContentAlignment.MiddleCenter;
gbxTunning.Controls.Add(lblTunned);
// Crea los radios para las distintas frecuencias: AM/FM
RadioButton rbnAm = new RadioButton();
rbnAm.AutoSize = true;
rbnAm.Location = new Point(61, 21);
rbnAm.Name = "rbnAm";
rbnAm.Text = "AM";
gbxTunning.Controls.Add(rbnAm);
RadioButton rbnPm = new RadioButton();
rbnPm.AutoSize = true;
rbnPm.Location = new Point(61, 41);
rbnPm.Name = "rbnPm";
rbnPm.Text = "PM";
gbxTunning.Controls.Add(rbnPm);
this.Controls.Add(gbxTunning);
}
///<summary>
/// Muestra en la interfaz del radio una imagen de una nota musical.
///</summary>
private void CreateJukebox()
{
// Crea la imagen para representar la nota musical.
PictureBox pbxJukebox = new PictureBox();
pbxJukebox.ImageLocation = "https://cdn4.iconfinder.com/data/icons/integral/128/key-256.png";
pbxJukebox.Location = new Point(337, 83);
pbxJukebox.Name = "pbxJukebox";
pbxJukebox.Size = new Size(55, 70);
pbxJukebox.SizeMode = PictureBoxSizeMode.StretchImage;
this.Controls.Add(pbxJukebox);
}
#endregion
#region CLIENT_CODE
///<summary>
/// Punto de entrada de la aplicación.
///</summary>
public static void Main()
{
Application.Run(new RadioGUI());
}
#endregion
}
}
view raw RadioGUI.cs hosted with ❤ by GitHub

No hay comentarios:

Publicar un comentario

Envíe sus comentarios, dudas, sugerencias, críticas. Gracias.