// ** P1 **
// > (x) %
// ( ) Voltios
// ( ) Decimal 0-1023
// ** P1 **
// > ATRÁS
// GUARDAR
using System;
namespace LCD_Menu_con_submenus_Consola_03.Ventana02
{
public class _0_P1
{
#region Variables.
// Contador de teclas y navegador.
static sbyte indiceSeleccionado = 0; // Índice seleccionado de cada opción del menú.
static bool salir = false; // Para salir del menú principal al INICIO.
const sbyte SELECCION_OPCIONES_TOTALES = 3; // Total de opciones para seleccionar y fija.
public static readonly string[] TEXTO
= new string[] {
" ** P1 ** ", // Posición 0.
" ( ) % ", // 1
" ( ) Voltios ", // 2
" ( ) Decimal 0-1023", // 3
" SALIR ", // 4
" ", // 5
">", // 6
"x" // 7
};
#endregion
public static void P1_Principal()
{
// Capturar tecla para luego validar.
ConsoleKey tecla;
// Limpiar pantalla.
Console.Clear();
do
{
//******************************************************************
// Dibujo el menú principal.
switch (indiceSeleccionado)
{
case 0:
Console.SetCursorPosition(0, 0);
Console.Write(TEXTO[0]); // ** P1 **
Console.SetCursorPosition(0, 1);
Console.Write(TEXTO[1]); // > ( ) %
Console.SetCursorPosition(0, 1);
Console.Write(TEXTO[6]); // >
Console.SetCursorPosition(0, 2);
Console.Write(TEXTO[2]); // ( ) Voltios
Console.SetCursorPosition(0, 3);
Console.Write(TEXTO[3]); // ( ) Decimal 0-1023
break;
case 1:
Console.SetCursorPosition(0, 0);
Console.Write(TEXTO[0]); // ** P1 **
Console.SetCursorPosition(0, 1);
Console.Write(TEXTO[1]); // ( ) %
Console.SetCursorPosition(0, 2);
Console.Write(TEXTO[2]); // > ( ) Voltios
Console.SetCursorPosition(0, 2);
Console.Write(TEXTO[6]); // >
Console.SetCursorPosition(0, 3);
Console.Write(TEXTO[3]); // ( ) Decimal 0-1023
break;
case 2:
Console.SetCursorPosition(0, 0);
Console.Write(TEXTO[0]); // ** P1 **
Console.SetCursorPosition(0, 1);
Console.Write(TEXTO[1]); // ( ) %
Console.SetCursorPosition(0, 2);
Console.Write(TEXTO[2]); // ( ) Voltios
Console.SetCursorPosition(0, 3);
Console.Write(TEXTO[3]); // > ( ) Decimal 0-1023
Console.SetCursorPosition(0, 3);
Console.Write(TEXTO[6]); // >
break;
case 3:
Console.SetCursorPosition(0, 0);
Console.Write(TEXTO[0]); // ** P1 **
Console.SetCursorPosition(0, 1);
Console.Write(TEXTO[4]); // > SALIR
Console.SetCursorPosition(0, 1);
Console.Write(TEXTO[6]); // >
Console.SetCursorPosition(0, 2);
Console.Write(TEXTO[5]); //
Console.SetCursorPosition(0, 3);
Console.Write(TEXTO[5]); //
break;
default:
Console.Write("Fuera de rango. ");
break;
}
// Fin de pintar el menú principal.
//******************************************************************
// Leer tecla ingresada por el usuario.
tecla = Console.ReadKey(true).Key;
// Validar el tipo de tecla.
if (tecla == ConsoleKey.Enter)
{
switch (indiceSeleccionado)
{
case 0:
Console.SetCursorPosition(3, 1);
Console.Write(TEXTO[7]); // x
break;
case 1:
Console.SetCursorPosition(3, 2);
Console.Write(TEXTO[7]); // x
break;
case 2:
Console.SetCursorPosition(3, 3);
Console.Write(TEXTO[7]); // x
break;
case 3:
salir = true; // Salir
break;
default:
Console.Write("Fuera de rango. ");
break;
}
}
// ¿Has pulsado tecla flecha Abajo?
else if (tecla == ConsoleKey.DownArrow)
{
indiceSeleccionado++;
}
// Entonces si pulsas tecla flecha Arriba.
else if (tecla == ConsoleKey.UpArrow)
{
indiceSeleccionado--;
}
// Si está en la última opción, salta a la primera.
if (indiceSeleccionado > SELECCION_OPCIONES_TOTALES)
{
indiceSeleccionado = 0;
}
// Si está en la primera posición, salta a la última.
if (indiceSeleccionado < 0)
{
indiceSeleccionado = SELECCION_OPCIONES_TOTALES;
}
// Uso la tecla escape como salida.
} while (!salir);
}
}
}