Ver Mensaje Individual
  #3  
Antiguo 08-08-2024
REHome REHome is offline
Miembro
 
Registrado: jul 2003
Ubicación: España
Posts: 475
Reputación: 23
REHome Va por buen camino
Segundo intento, sigue teniendo mucho código. Si funciona.

Código:
using System;

namespace Pruebas_Opciones_Consola_01
{
    internal class Program
    {
        static void Main(string[] args)
        {
            #region Configuración ventana.
            // Título de la ventana.
            Console.Title = "Opciones";

            // Tamaño de la ventana, x, y o, ancho y alto.
            const byte ancho = 20, alto = 5;
            Console.SetWindowSize(ancho, alto);

            // Quitar scroll laterales. Derecho y abajo.
            Console.SetBufferSize(ancho, alto);

            // Color de fondo.
            Console.BackgroundColor = ConsoleColor.Yellow;

            // Color de las letras.
            Console.ForegroundColor = ConsoleColor.Black;

            // Limpiar pantalla y dejarlo todo en color de fondo.
            Console.Clear();

            // Visible el cursor. // No! Así lo haces invisible.
            Console.CursorVisible = false;
            #endregion

            string[] opciones =
{
                    "    ** TÍTULO **    ",    // Posición 0.
                    "  ( ) Opción A      ",    // 1
                    "  ( ) Opción B      ",    // 2
                    "  ( ) Opción C      ",    // 3
                    "  SALIR             ",    // 4
                    ">",                       // 5
                    "x",                       // 6
                    " ",                       // 7
                    "                    "     // 8
                };

            Menu();
            #region Opociones y selecciones
            void OpcionesA()
            {
                Console.SetCursorPosition(0, 0);
                Console.Write(opciones[0]);       //    ** TÍTULO **    
                Console.SetCursorPosition(0, 1);
                Console.Write(opciones[1]);       //   ( ) Opción A
                Console.SetCursorPosition(0, 2);
                Console.Write(opciones[2]);       //   ( ) Opción B
                Console.SetCursorPosition(0, 3);
                Console.Write(opciones[3]);       //   ( ) Opción C 
            }

            void OpcionesB()
            {
                Console.SetCursorPosition(0, 1);
                Console.Write(opciones[4]);       //   SALIR
                Console.SetCursorPosition(0, 2);
                Console.Write(opciones[8]);       //  
                Console.SetCursorPosition(0, 3);
                Console.Write(opciones[8]);       // 
            }

            void SelectorA()
            {
                Console.SetCursorPosition(0, 1);
                Console.Write(opciones[5]);       // >
                Console.SetCursorPosition(0, 2);
                Console.Write(opciones[7]);
                Console.SetCursorPosition(0, 3);
                Console.Write(opciones[7]);
            }

            void SelectorB()
            {
                Console.SetCursorPosition(0, 1);
                Console.Write(opciones[7]);       
                Console.SetCursorPosition(0, 2);
                Console.Write(opciones[5]);       // >
                Console.SetCursorPosition(0, 3);
                Console.Write(opciones[7]);
            }

            void SelectorC()
            {
                Console.SetCursorPosition(0, 1);
                Console.Write(opciones[7]);
                Console.SetCursorPosition(0, 2);
                Console.Write(opciones[7]);       
                Console.SetCursorPosition(0, 3);
                Console.Write(opciones[5]);        // >
            }
            #endregion

            void Menu()
            {
                sbyte indiceSeleccionado = 0;                // Índice seleccionado de cada opción del menú.
                bool salir = false;                          // Para salir del menú principal al INICIO.
                sbyte SELECCION_OPCIONES_TOTALES = 3;        // Total de opciones para seleccionar y fija.

                string opA = "x";
                string opB = " ";
                string opC = " ";

                // Capturar tecla para luego validar.
                ConsoleKey tecla;

                do
                {
                    //******************************************************************
                    // Dibujo el menú principal.

                    switch (indiceSeleccionado)
                    {
                        case 0:
                            OpcionesA();
                            SelectorA();
                            Console.SetCursorPosition(3, 1);
                            Console.Write(opA);
                            Console.SetCursorPosition(3, 2);
                            Console.Write(opB);
                            Console.SetCursorPosition(3, 3);
                            Console.Write(opC);
                            break;

                        case 1:
                            OpcionesA();
                            SelectorB();
                            Console.SetCursorPosition(3, 1);
                            Console.Write(opA);
                            Console.SetCursorPosition(3, 2);
                            Console.Write(opB);
                            Console.SetCursorPosition(3, 3);
                            Console.Write(opC);
                            break;

                        case 2:
                            OpcionesA();
                            SelectorC();
                            Console.SetCursorPosition(3, 1);
                            Console.Write(opA);
                            Console.SetCursorPosition(3, 2);
                            Console.Write(opB);
                            Console.SetCursorPosition(3, 3);
                            Console.Write(opC);
                            break;

                        case 3:
                            OpcionesB();
                            Console.SetCursorPosition(0, 1);
                            Console.Write(opciones[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:
                                opA = "x"; opB = " "; opC = " ";
                                break;

                            case 1:
                                opA = " "; opB = "x"; opC = " ";
                                break;

                            case 2:
                                opA = " "; opB = " "; opC = "x";
                                break;

                            case 3:
                                indiceSeleccionado = 0; // Restaurar índice antes de salir.
                                salir = true;           // Salir
                                break;

                            default:
                                Console.Write("Fuera de rango.     ");
                                break;
                        }
                    }

                    // ¿Has pulsado tecla flecha Abajo?
                    if (tecla == ConsoleKey.DownArrow)
                    {
                        indiceSeleccionado++;
                    }

                    // Entonces si pulsas tecla flecha Arriba.
                    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);
            }
        }
    }
}
__________________
http://electronica-pic.blogspot.com....n-arduino.html Manuales de electrónica general, PIC y Arduino.
Responder Con Cita