elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Hacer un menú básico como la época de antes en modo consola
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Hacer un menú básico como la época de antes en modo consola  (Leído 2,554 veces)
Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Hacer un menú básico como la época de antes en modo consola
« en: 28 Marzo 2015, 18:10 pm »

Hola:

Quiero hacer un menú de configuración del puerto serie. No me centraré en como hacer funcionar el puerto serie, lo haré más delante y lo explica por aquí.

Quiero hacerlo de la mejor forma, a pesar que este tipo de técnica se usaba en la época de MS-DOS y más allá, me he encaprichado en hacerlo así ya por hobby, hehehehe. ;)

Quiero que me den ideas de como hacerlo, por ahora lo he hecho así muy básico, que pueda entrar en menús y submenus para vuelva a empezar del menú desde el principio.

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.IO.Ports; // No olvidar.
  8. using System.Threading;
  9.  
  10. namespace PuertoCOM_CS_PRUEBA
  11. {
  12.    class Program
  13.    {
  14.        static void Main(string[] args)
  15.        {
  16.            Console.Title = "Interfaz puerto serie - v0.01"; // Mostrar título en la ventana de la consola.
  17.  
  18.            string Comandos_teclado = Console.Read();
  19.  
  20.            string Menu_Principal = @"========== MENÚ PRINCIPAL ==========
  21.  
  22.  
  23.            0) Menú principa.
  24.            1) Interfaz.
  25.            2) Configuración.
  26.            3) Guardar configuración.
  27.            4) Ayuda.";
  28.  
  29.  
  30.            int switchExpression = 3;
  31.            switch (switchExpression)
  32.            {
  33.                case 0:
  34.                    Console.WriteLine(Menu_Principal);
  35.                    break;
  36.  
  37.                case 1:
  38.                    Console.WriteLine("===== INTERFAZ =====");
  39.                    Console.WriteLine("Pulse 0 para vovler al menú principal.");
  40.                    break;
  41.  
  42.                case 2:
  43.                    Console.WriteLine("===== CONFIGURACIÓN =====");
  44.                    Console.WriteLine("Pulse 0 para vovler al menú principal.");
  45.                    break;
  46.  
  47.                case 3:
  48.                    Console.WriteLine("===== Guadar configuración =====");
  49.                    Console.WriteLine("Pulse 0 para vovler al menú principal.");
  50.                    break;
  51.  
  52.                case 4:
  53.                    Console.WriteLine("===== Ayuda =====");
  54.                    Console.WriteLine("Pulse 0 para vovler al menú principal.");
  55.                    break;
  56.  
  57.                default:
  58.                    Console.WriteLine("No has elegido nunguna opción. Vuelva teclear del 0 al 4.");
  59.                    break;
  60.            }
  61.  
  62.        }
  63.    }
  64. }

Aquí todo sobre Swicht.

Pueden darme consejos de cómo lo harían ustedes.

Saludos.


En línea

Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Re: Hacer un menú básico como la época de antes en modo consola
« Respuesta #1 en: 28 Marzo 2015, 20:09 pm »

Una mejora que funciona mejor.

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.IO.Ports; // No olvidar.
  8. using System.Threading;
  9.  
  10. namespace PuertoCOM_CS_PRUEBA
  11. {
  12.    class Program
  13.    {
  14.        static void Main(string[] args)
  15.        {
  16.            new Program().Modal();
  17.        }
  18.  
  19.        void Modal()
  20.        {
  21.            for (; ; )
  22.            {
  23.                Console.Title = "Interfaz puerto serie - v0.03"; // Mostrar título en la ventana de la consola.
  24.  
  25.  
  26.                string Menu_Principal = @"========== MENÚ PRINCIPAL ==========
  27.  
  28.  
  29.            0) Salir.
  30.            1) Interfaz.
  31.            2) Configuración.
  32.            3) Guardar configuración.
  33.            4) Ayuda.
  34.  
  35.  
  36. ";
  37.  
  38.                Console.Clear();
  39.                Console.Write(Menu_Principal);
  40.                ConsoleKeyInfo switchExpression = Console.ReadKey();
  41.                switch (switchExpression.KeyChar)
  42.                {
  43.                    case '0':
  44.                        return;
  45.  
  46.                    case '1':
  47.                        new Interfaz().Modal();
  48.                        break;
  49.  
  50.                    case '2':
  51.                        new Configuracion().Modal();
  52.                        break;
  53.  
  54.                    case '3':
  55.                        new Guardar_Configuracion().Modal();
  56.                        break;
  57.  
  58.                    case '4':
  59.                        new Ayuda().Modal();
  60.                        break;
  61.  
  62.                    default:
  63.                        Console.WriteLine("No has elegido nunguna opción. Vuelva teclear del 0 al 4.");
  64.                        break;
  65.                }
  66.            }
  67.  
  68.        }
  69.    }
  70.  
  71.    class Interfaz
  72.    {
  73.        public void Modal()
  74.        {
  75.            for (; ; )
  76.            {
  77.                Console.Clear();
  78.                Console.WriteLine("===== INTERFAZ =====");
  79.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  80.  
  81.                ConsoleKeyInfo op = Console.ReadKey();
  82.  
  83.                switch (op.KeyChar)
  84.                {
  85.                    case '0':
  86.                        return;
  87.  
  88.                    default:
  89.                        break;
  90.                }
  91.            }
  92.        }
  93.    }
  94.  
  95.    class Configuracion
  96.    {
  97.        public void Modal()
  98.        {
  99.            for (; ; )
  100.            {
  101.                Console.Clear();
  102.                Console.WriteLine("===== CONFIGURACIÓN =====");
  103.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  104.  
  105.                ConsoleKeyInfo op = Console.ReadKey();
  106.  
  107.                switch (op.KeyChar)
  108.                {
  109.                    case '0':
  110.                        return;
  111.  
  112.                    default:
  113.                        break;
  114.                }
  115.            }
  116.        }
  117.    }
  118.  
  119.    class Guardar_Configuracion
  120.    {
  121.        public void Modal()
  122.        {
  123.            for (; ; )
  124.            {
  125.                Console.Clear();
  126.                Console.WriteLine("===== Guadar configuración =====");
  127.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  128.  
  129.                ConsoleKeyInfo op = Console.ReadKey();
  130.  
  131.                switch (op.KeyChar)
  132.                {
  133.                    case '0':
  134.                        return;
  135.  
  136.                    default:
  137.                        break;
  138.                }
  139.            }
  140.        }
  141.    }
  142.  
  143.    class Ayuda
  144.    {
  145.        public void Modal()
  146.        {
  147.            for (; ; )
  148.            {
  149.                Console.Clear();
  150.                Console.WriteLine("===== Ayuda =====");
  151.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  152.  
  153.                ConsoleKeyInfo op = Console.ReadKey();
  154.  
  155.                switch (op.KeyChar)
  156.                {
  157.                    case '0':
  158.                        return;
  159.  
  160.                    default:
  161.                        break;
  162.                }
  163.            }
  164.        }
  165.    }
  166. }
  167.  

Aún así quiero sugerencia para hacerlo lo mejor posible.

Saludos.


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.818



Ver Perfil
Re: Hacer un menú básico como la época de antes en modo consola
« Respuesta #2 en: 28 Marzo 2015, 22:22 pm »

Pueden darme consejos de cómo lo harían ustedes.

Yo quizás lo hiciese de la siguiente manera...



Por un lado una Class para definir un item de menu:

Código
  1.    ''' <summary>
  2.    ''' Defines a Console Menu Item.
  3.    ''' </summary>
  4.    Public NotInheritable Class ConsoleMenuItem
  5.  
  6.        ''' <summary>
  7.        ''' Gets or sets the item text.
  8.        ''' </summary>
  9.        ''' <value>The item text.</value>
  10.        Public Property Text As String
  11.  
  12.        ''' <summary>
  13.        ''' Gets or sets the <see cref="ConsoleKey"/> that activates this item.
  14.        ''' </summary>
  15.        ''' <value>The <see cref="ConsoleKey"/> that activates this item.</value>
  16.        Public Property Key As ConsoleKey
  17.  
  18.        ''' <summary>
  19.        ''' Gets or sets the associated <see cref="Command"/> for this item.
  20.        ''' </summary>
  21.        ''' <value>The associated <see cref="Command"/> for this item.</value>
  22.        Public Property Command As Action
  23.  
  24.    End Class

Con ello, compongo los items del menú y sub-menúes:

Código
  1.    ''' <summary>
  2.    ''' The main menu items.
  3.    ''' </summary>
  4.    Private ReadOnly mainMenuItems As IEnumerable(Of ConsoleMenuItem) =
  5.        {
  6.            New ConsoleMenuItem With
  7.                {
  8.                    .Text = "[1] Show first submenu",
  9.                    .Key = ConsoleKey.D1,
  10.                    .Command = New Action(Sub()
  11.                                              ShowMenu(subMenuItems1)
  12.                                          End Sub)
  13.                },
  14.            New ConsoleMenuItem With
  15.                {
  16.                    .Text = "[2] Show second submenu",
  17.                    .Key = ConsoleKey.D2,
  18.                    .Command = New Action(Sub()
  19.                                              ShowMenu(subMenuItems2)
  20.                                          End Sub)},
  21.            menuItemExit
  22.        }
  23.  
  24.    ''' <summary>
  25.    ''' The first submenu items.
  26.    ''' </summary>
  27.    Private ReadOnly subMenuItems1 As IEnumerable(Of ConsoleMenuItem) =
  28.        {
  29.            New ConsoleMenuItem With
  30.                {
  31.                    .Text = "[1] Print a 'Hello World!'",
  32.                    .Key = ConsoleKey.D1,
  33.                    .Command = New Action(Sub()
  34.                                              Console.WriteLine("Hello World!")
  35.                                          End Sub)
  36.                },
  37.            New ConsoleMenuItem With
  38.                {
  39.                    .Text = "[R] Return",
  40.                    .Key = ConsoleKey.R,
  41.                    .Command = New Action(Sub()
  42.                                              ShowMenu(mainMenuItems)
  43.                                          End Sub)},
  44.            menuItemExit
  45.        }
  46.  
  47.    ''' <summary>
  48.    ''' The second submenu items.
  49.    ''' </summary>
  50.    Private ReadOnly subMenuItems2 As IEnumerable(Of ConsoleMenuItem) =
  51.        {
  52.            New ConsoleMenuItem With
  53.                {
  54.                    .Text = "[1] Print the current date.",
  55.                    .Key = ConsoleKey.D1,
  56.                    .Command = Sub()
  57.                                   Console.WriteLine(Date.Today.ToLongDateString)
  58.                               End Sub
  59.                },
  60.            New ConsoleMenuItem With
  61.                {
  62.                    .Text = "[R] Return",
  63.                    .Key = ConsoleKey.R,
  64.                    .Command = New Action(Sub()
  65.                                              ShowMenu(mainMenuItems)
  66.                                          End Sub)},
  67.            menuItemExit
  68.        }
  69.  
  70.    ''' <summary>
  71.    ''' A menu item that exists from console.
  72.    ''' </summary>
  73.    Private ReadOnly menuItemExit As New ConsoleMenuItem With
  74.    {
  75.        .Text = "[X] Exit...",
  76.        .Key = ConsoleKey.X,
  77.        .Command = AddressOf EndConsole
  78.    }

El resto ya solo es darle el formato de texto deseado al menú, y procesar la entrada del teclado:

Código
  1.    ''' <summary>
  2.    ''' Defines the entry point of the application.
  3.    ''' </summary>
  4.    Public Sub Main()
  5.  
  6.        ShowMenu(mainMenuItems)
  7.        System.Threading.Thread.Sleep(Integer.MaxValue)
  8.  
  9.    End Sub
  10.  
  11.    ''' <summary>
  12.    ''' Shows a console menu.
  13.    ''' </summary>
  14.    ''' <param name="menuItems">The items that composes the menu.</param>
  15.    ''' <param name="itemIndicator">A string that indicates the current menu item.</param>
  16.    Private Sub ShowMenu(ByVal menuItems As IEnumerable(Of ConsoleMenuItem),
  17.                         Optional ByVal itemIndicator As String = " -> ")
  18.  
  19.        ' The selected menu item.
  20.        Dim selectedItem As ConsoleMenuItem = menuItems(0)
  21.  
  22.        ' The index of the selected menu item.
  23.        Dim selectedIndex As Integer
  24.  
  25.        ' The object to read the user-input pressed key.
  26.        Dim currentKey As ConsoleKey
  27.  
  28.        ' Flag that determines wether the user pressed a valid menu item key.
  29.        Dim itemKeyIsPressed As Boolean
  30.  
  31.        ' Wait for a valid menu item key.
  32.        Do Until itemKeyIsPressed
  33.  
  34.            ' Iterate the menu items to format the menu string.
  35.            Dim sb As New System.Text.StringBuilder
  36.            With sb
  37.  
  38.                sb.AppendLine("===============================")
  39.                sb.AppendLine("=========== My Menu ===========")
  40.                sb.AppendLine("===============================")
  41.                sb.AppendLine()
  42.  
  43.                For Each menuItem As ConsoleMenuItem In menuItems
  44.                    If menuItem Is selectedItem Then
  45.                        sb.AppendLine(String.Format("{0}{1}", itemIndicator, menuItem.Text))
  46.                    Else
  47.                        sb.AppendLine(menuItem.Text.Insert(0, New String(" "c, itemIndicator.Length)))
  48.                    End If
  49.                Next menuItem
  50.  
  51.                sb.AppendLine()
  52.                sb.AppendLine("===============================")
  53.  
  54.            End With
  55.  
  56.            ' Clear the screen.
  57.            Console.Clear()
  58.  
  59.            ' Print the menu items.
  60.            Console.WriteLine(sb.ToString)
  61.  
  62.            ' Wait for user-input.
  63.            currentKey = Console.ReadKey(True).Key
  64.  
  65.            ' Handle the pressed key.
  66.            Select Case currentKey
  67.  
  68.                Case ConsoleKey.DownArrow ' Decrease current item selection.
  69.                    selectedIndex = menuItems.ToList.IndexOf(selectedItem)
  70.                    If selectedIndex < (menuItems.Count - 1) Then
  71.                        selectedItem = menuItems(selectedIndex + 1)
  72.                    Else
  73.                        selectedItem = menuItems.First
  74.                    End If
  75.  
  76.                Case ConsoleKey.UpArrow  ' Increase current item selection.
  77.                    selectedIndex = menuItems.ToList.IndexOf(selectedItem)
  78.                    If selectedIndex <> 0 Then
  79.                        selectedItem = menuItems(selectedIndex - 1)
  80.                    Else
  81.                        selectedItem = menuItems.Last
  82.                    End If
  83.  
  84.                Case ConsoleKey.Enter ' Run the selected item's command.
  85.                    itemKeyIsPressed = True
  86.                    selectedItem.Command.Invoke()
  87.  
  88.                Case ConsoleKey.Backspace ' Return to previous menu (if any).
  89.                    Dim foundItem As ConsoleMenuItem =
  90.                        (From item As ConsoleMenuItem In menuItems
  91.                         Where item.Key = ConsoleKey.R).FirstOrDefault
  92.  
  93.                    If foundItem IsNot Nothing Then
  94.                        itemKeyIsPressed = True
  95.                        selectedItem = foundItem
  96.                        selectedItem.Command.Invoke()
  97.                    End If
  98.  
  99.                Case Else
  100.                    Dim foundItem As ConsoleMenuItem =
  101.                        (From item As ConsoleMenuItem In menuItems
  102.                         Where item.Key = currentKey).FirstOrDefault
  103.  
  104.                    If foundItem IsNot Nothing Then
  105.                        itemKeyIsPressed = True
  106.                        selectedItem = foundItem
  107.                        selectedItem.Command.Invoke()
  108.                    End If
  109.  
  110.            End Select
  111.  
  112.        Loop
  113.  
  114.    End Sub
  115.  
  116.    ''' <summary>
  117.    ''' Terminates the application.
  118.    ''' </summary>
  119.    Private Sub EndConsole()
  120.  
  121.        Environment.Exit(exitCode:=0)
  122.  
  123.    End Sub



El source completo, en VB:

Código
  1. Module Module1
  2.  
  3.    ''' <summary>
  4.    ''' Defines a Console Menu Item.
  5.    ''' </summary>
  6.    Public NotInheritable Class ConsoleMenuItem
  7.  
  8.        ''' <summary>
  9.        ''' Gets or sets the item text.
  10.        ''' </summary>
  11.        ''' <value>The item text.</value>
  12.        Public Property Text As String
  13.  
  14.        ''' <summary>
  15.        ''' Gets or sets the <see cref="ConsoleKey"/> that activates this item.
  16.        ''' </summary>
  17.        ''' <value>The <see cref="ConsoleKey"/> that activates this item.</value>
  18.        Public Property Key As ConsoleKey
  19.  
  20.        ''' <summary>
  21.        ''' Gets or sets the associated <see cref="Command"/> for this item.
  22.        ''' </summary>
  23.        ''' <value>The associated <see cref="Command"/> for this item.</value>
  24.        Public Property Command As Action
  25.  
  26.    End Class
  27.  
  28.    ''' <summary>
  29.    ''' A menu item that exists from console.
  30.    ''' </summary>
  31.    Private ReadOnly menuItemExit As New ConsoleMenuItem With
  32.    {
  33.        .Text = "[X] Exit...",
  34.        .Key = ConsoleKey.X,
  35.        .Command = AddressOf EndConsole
  36.    }
  37.  
  38.    ''' <summary>
  39.    ''' The main menu items.
  40.    ''' </summary>
  41.    Private ReadOnly mainMenuItems As IEnumerable(Of ConsoleMenuItem) =
  42.        {
  43.            New ConsoleMenuItem With
  44.                {
  45.                    .Text = "[1] Show first submenu",
  46.                    .Key = ConsoleKey.D1,
  47.                    .Command = New Action(Sub()
  48.                                              ShowMenu(subMenuItems1)
  49.                                          End Sub)
  50.                },
  51.            New ConsoleMenuItem With
  52.                {
  53.                    .Text = "[2] Show second submenu",
  54.                    .Key = ConsoleKey.D2,
  55.                    .Command = New Action(Sub()
  56.                                              ShowMenu(subMenuItems2)
  57.                                          End Sub)},
  58.            menuItemExit
  59.        }
  60.  
  61.    ''' <summary>
  62.    ''' The first submenu items.
  63.    ''' </summary>
  64.    Private ReadOnly subMenuItems1 As IEnumerable(Of ConsoleMenuItem) =
  65.        {
  66.            New ConsoleMenuItem With
  67.                {
  68.                    .Text = "[1] Print a 'Hello World!'",
  69.                    .Key = ConsoleKey.D1,
  70.                    .Command = New Action(Sub()
  71.                                              Console.WriteLine("Hello World!")
  72.                                          End Sub)
  73.                },
  74.            New ConsoleMenuItem With
  75.                {
  76.                    .Text = "[R] Return",
  77.                    .Key = ConsoleKey.R,
  78.                    .Command = New Action(Sub()
  79.                                              ShowMenu(mainMenuItems)
  80.                                          End Sub)},
  81.            menuItemExit
  82.        }
  83.  
  84.    ''' <summary>
  85.    ''' The second submenu items.
  86.    ''' </summary>
  87.    Private ReadOnly subMenuItems2 As IEnumerable(Of ConsoleMenuItem) =
  88.        {
  89.            New ConsoleMenuItem With
  90.                {
  91.                    .Text = "[1] Print the current date.",
  92.                    .Key = ConsoleKey.D1,
  93.                    .Command = Sub()
  94.                                   Console.WriteLine(Date.Today.ToLongDateString)
  95.                               End Sub
  96.                },
  97.            New ConsoleMenuItem With
  98.                {
  99.                    .Text = "[R] Return",
  100.                    .Key = ConsoleKey.R,
  101.                    .Command = New Action(Sub()
  102.                                              ShowMenu(mainMenuItems)
  103.                                          End Sub)},
  104.            menuItemExit
  105.        }
  106.  
  107.    ''' <summary>
  108.    ''' Defines the entry point of the application.
  109.    ''' </summary>
  110.    Public Sub Main()
  111.  
  112.        ShowMenu(mainMenuItems)
  113.        System.Threading.Thread.Sleep(Integer.MaxValue)
  114.  
  115.    End Sub
  116.  
  117.    ''' <summary>
  118.    ''' Shows a console menu.
  119.    ''' </summary>
  120.    ''' <param name="menuItems">The items that composes the menu.</param>
  121.    ''' <param name="itemIndicator">A string that indicates the current menu item.</param>
  122.    Private Sub ShowMenu(ByVal menuItems As IEnumerable(Of ConsoleMenuItem),
  123.                         Optional ByVal itemIndicator As String = " -> ")
  124.  
  125.        ' The selected menu item.
  126.        Dim selectedItem As ConsoleMenuItem = menuItems(0)
  127.  
  128.        ' The index of the selected menu item.
  129.        Dim selectedIndex As Integer
  130.  
  131.        ' The object to read the user-input pressed key.
  132.        Dim currentKey As ConsoleKey
  133.  
  134.        ' Flag that determines wether the user pressed a valid menu item key.
  135.        Dim itemKeyIsPressed As Boolean
  136.  
  137.        ' Wait for a valid menu item key.
  138.        Do Until itemKeyIsPressed
  139.  
  140.            ' Iterate the menu items to format the menu string.
  141.            Dim sb As New System.Text.StringBuilder
  142.            With sb
  143.  
  144.                sb.AppendLine("===============================")
  145.                sb.AppendLine("=========== My Menu ===========")
  146.                sb.AppendLine("===============================")
  147.                sb.AppendLine()
  148.  
  149.                For Each menuItem As ConsoleMenuItem In menuItems
  150.                    If menuItem Is selectedItem Then
  151.                        sb.AppendLine(String.Format("{0}{1}", itemIndicator, menuItem.Text))
  152.                    Else
  153.                        sb.AppendLine(menuItem.Text.Insert(0, New String(" "c, itemIndicator.Length)))
  154.                    End If
  155.                Next menuItem
  156.  
  157.                sb.AppendLine()
  158.                sb.AppendLine("===============================")
  159.  
  160.            End With
  161.  
  162.            ' Clear the screen.
  163.            Console.Clear()
  164.  
  165.            ' Print the menu items.
  166.            Console.WriteLine(sb.ToString)
  167.  
  168.            ' Wait for user-input.
  169.            currentKey = Console.ReadKey(True).Key
  170.  
  171.            ' Handle the pressed key.
  172.            Select Case currentKey
  173.  
  174.                Case ConsoleKey.DownArrow ' Decrease current item selection.
  175.                    selectedIndex = menuItems.ToList.IndexOf(selectedItem)
  176.                    If selectedIndex < (menuItems.Count - 1) Then
  177.                        selectedItem = menuItems(selectedIndex + 1)
  178.                    Else
  179.                        selectedItem = menuItems.First
  180.                    End If
  181.  
  182.                Case ConsoleKey.UpArrow  ' Increase current item selection.
  183.                    selectedIndex = menuItems.ToList.IndexOf(selectedItem)
  184.                    If selectedIndex <> 0 Then
  185.                        selectedItem = menuItems(selectedIndex - 1)
  186.                    Else
  187.                        selectedItem = menuItems.Last
  188.                    End If
  189.  
  190.                Case ConsoleKey.Enter ' Run the selected item's command.
  191.                    itemKeyIsPressed = True
  192.                    selectedItem.Command.Invoke()
  193.  
  194.                Case ConsoleKey.Backspace ' Return to previous menu (if any).
  195.                    Dim foundItem As ConsoleMenuItem =
  196.                        (From item As ConsoleMenuItem In menuItems
  197.                         Where item.Key = ConsoleKey.R).FirstOrDefault
  198.  
  199.                    If foundItem IsNot Nothing Then
  200.                        itemKeyIsPressed = True
  201.                        selectedItem = foundItem
  202.                        selectedItem.Command.Invoke()
  203.                    End If
  204.  
  205.                Case Else
  206.                    Dim foundItem As ConsoleMenuItem =
  207.                        (From item As ConsoleMenuItem In menuItems
  208.                         Where item.Key = currentKey).FirstOrDefault
  209.  
  210.                    If foundItem IsNot Nothing Then
  211.                        itemKeyIsPressed = True
  212.                        selectedItem = foundItem
  213.                        selectedItem.Command.Invoke()
  214.                    End If
  215.  
  216.            End Select
  217.  
  218.        Loop
  219.  
  220.    End Sub
  221.  
  222.    ''' <summary>
  223.    ''' Terminates the application.
  224.    ''' </summary>
  225.    Private Sub EndConsole()
  226.  
  227.        Environment.Exit(exitCode:=0)
  228.  
  229.    End Sub
  230.  
  231. End Module

Traducción online a C# (sin testear):
Código
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7.  
  8. static class Module1
  9. {
  10. /// <summary>
  11. /// Defines a Console Menu Item.
  12. /// </summary>
  13. public sealed class ConsoleMenuItem
  14. {
  15. /// <summary>
  16. /// Gets or sets the item text.
  17. /// </summary>
  18. /// <value>The item text.</value>
  19. public string Text { get; set; }
  20.  
  21. /// <summary>
  22. /// Gets or sets the <see cref="ConsoleKey"/> that activates this item.
  23. /// </summary>
  24. /// <value>The <see cref="ConsoleKey"/> that activates this item.</value>
  25. public ConsoleKey Key { get; set; }
  26.  
  27. /// <summary>
  28. /// Gets or sets the associated <see cref="Command"/> for this item.
  29. /// </summary>
  30. /// <value>The associated <see cref="Command"/> for this item.</value>
  31. public Action Command { get; set; }
  32.  
  33. }
  34.  
  35. /// <summary>
  36. /// A menu item that exists from console.
  37. /// </summary>
  38. private static readonly ConsoleMenuItem menuItemExit = new ConsoleMenuItem {
  39. Text = "[X] Exit...",
  40. Key = ConsoleKey.X,
  41. Command = EndConsole
  42.  
  43. };
  44. /// <summary>
  45. /// The main menu items.
  46. /// </summary>
  47. private static readonly IEnumerable<ConsoleMenuItem> mainMenuItems = {
  48. new ConsoleMenuItem {
  49. Text = "[1] Show first submenu",
  50. Key = ConsoleKey.D1,
  51. Command = new Action(() => { ShowMenu(subMenuItems1); })
  52. },
  53. new ConsoleMenuItem {
  54. Text = "[2] Show second submenu",
  55. Key = ConsoleKey.D2,
  56. Command = new Action(() => { ShowMenu(subMenuItems2); })
  57. },
  58. menuItemExit
  59.  
  60. };
  61. /// <summary>
  62. /// The first submenu items.
  63. /// </summary>
  64. private static readonly IEnumerable<ConsoleMenuItem> subMenuItems1 = {
  65. new ConsoleMenuItem {
  66. Text = "[1] Print a 'Hello World!'",
  67. Key = ConsoleKey.D1,
  68. Command = new Action(() => { Console.WriteLine("Hello World!"); })
  69. },
  70. new ConsoleMenuItem {
  71. Text = "[R] Return",
  72. Key = ConsoleKey.R,
  73. Command = new Action(() => { ShowMenu(mainMenuItems); })
  74. },
  75. menuItemExit
  76.  
  77. };
  78. /// <summary>
  79. /// The second submenu items.
  80. /// </summary>
  81. private static readonly IEnumerable<ConsoleMenuItem> subMenuItems2 = {
  82. new ConsoleMenuItem {
  83. Text = "[1] Print the current date.",
  84. Key = ConsoleKey.D1,
  85. Command = () => { Console.WriteLine(System.DateTime.Today.ToLongDateString); }
  86. },
  87. new ConsoleMenuItem {
  88. Text = "[R] Return",
  89. Key = ConsoleKey.R,
  90. Command = new Action(() => { ShowMenu(mainMenuItems); })
  91. },
  92. menuItemExit
  93.  
  94. };
  95. /// <summary>
  96. /// Defines the entry point of the application.
  97. /// </summary>
  98.  
  99. public static void Main()
  100. {
  101. ShowMenu(mainMenuItems);
  102. System.Threading.Thread.Sleep(int.MaxValue);
  103. }
  104.  
  105. /// <summary>
  106. /// Shows a console menu.
  107. /// </summary>
  108. /// <param name="menuItems">The items that composes the menu.</param>
  109. /// <param name="itemIndicator">A string that indicates the current menu item.</param>
  110.  
  111. private static void ShowMenu(IEnumerable<ConsoleMenuItem> menuItems, string itemIndicator = " -> ")
  112. {
  113. // The selected menu item.
  114. ConsoleMenuItem selectedItem = menuItems(0);
  115.  
  116. // The index of the selected menu item.
  117. int selectedIndex = 0;
  118.  
  119. // The object to read the user-input pressed key.
  120. ConsoleKey currentKey = default(ConsoleKey);
  121.  
  122. // Flag that determines wether the user pressed a valid menu item key.
  123. bool itemKeyIsPressed = false;
  124.  
  125. // Wait for a valid menu item key.
  126.  
  127. while (!(itemKeyIsPressed)) {
  128. // Iterate the menu items to format the menu string.
  129. System.Text.StringBuilder sb = new System.Text.StringBuilder();
  130. var _with1 = sb;
  131.  
  132. sb.AppendLine("===============================");
  133. sb.AppendLine("=========== My Menu ===========");
  134. sb.AppendLine("===============================");
  135. sb.AppendLine();
  136.  
  137. foreach (ConsoleMenuItem menuItem in menuItems) {
  138. if (object.ReferenceEquals(menuItem, selectedItem)) {
  139. sb.AppendLine(string.Format("{0}{1}", itemIndicator, menuItem.Text));
  140. } else {
  141. sb.AppendLine(menuItem.Text.Insert(0, new string(' ', itemIndicator.Length)));
  142. }
  143. }
  144.  
  145. sb.AppendLine();
  146. sb.AppendLine("===============================");
  147.  
  148.  
  149. // Clear the screen.
  150. Console.Clear();
  151.  
  152. // Print the menu items.
  153. Console.WriteLine(sb.ToString);
  154.  
  155. // Wait for user-input.
  156. currentKey = Console.ReadKey(true).Key;
  157.  
  158. // Handle the pressed key.
  159. switch (currentKey) {
  160.  
  161. case ConsoleKey.DownArrow:
  162. // Decrease current item selection.
  163. selectedIndex = menuItems.ToList.IndexOf(selectedItem);
  164. if (selectedIndex < (menuItems.Count - 1)) {
  165. selectedItem = menuItems(selectedIndex + 1);
  166. } else {
  167. selectedItem = menuItems.First;
  168. }
  169.  
  170. break;
  171. case ConsoleKey.UpArrow:
  172. // Increase current item selection.
  173. selectedIndex = menuItems.ToList.IndexOf(selectedItem);
  174. if (selectedIndex != 0) {
  175. selectedItem = menuItems(selectedIndex - 1);
  176. } else {
  177. selectedItem = menuItems.Last;
  178. }
  179.  
  180. break;
  181. case ConsoleKey.Enter:
  182. // Run the selected item's command.
  183. itemKeyIsPressed = true;
  184. selectedItem.Command.Invoke();
  185.  
  186. break;
  187. case ConsoleKey.Backspace:
  188. // Return to previous menu (if any).
  189. ConsoleMenuItem foundItem = (from item in menuItemswhere item.Key == ConsoleKey.R).FirstOrDefault;
  190.  
  191. if (foundItem != null) {
  192. itemKeyIsPressed = true;
  193. selectedItem = foundItem;
  194. selectedItem.Command.Invoke();
  195. }
  196.  
  197. break;
  198. default:
  199. ConsoleMenuItem foundItem = (from item in menuItemswhere item.Key == currentKey).FirstOrDefault;
  200.  
  201. if (foundItem != null) {
  202. itemKeyIsPressed = true;
  203. selectedItem = foundItem;
  204. selectedItem.Command.Invoke();
  205. }
  206. break;
  207. }
  208. }
  209. }
  210.  
  211. /// <summary>
  212. /// Terminates the application.
  213. /// </summary>
  214. private static void EndConsole()
  215. {
  216. Environment.Exit(exitCode: 0);
  217. }
  218. }
  219.  
  220. //=======================================================
  221. //Service provided by Telerik (www.telerik.com)
  222. //Facebook: facebook.com/telerik
  223. //=======================================================
  224.  

Saludos
En línea

Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
Re: Hacer un menú básico como la época de antes en modo consola
« Respuesta #3 en: 29 Marzo 2015, 15:04 pm »

Gracias.

Lo he estado analizando, a pesar de tener buenos resultados, para mi es complicado. Seguiré con lo que iba.

Tengo más o menos los menús hecho en modo consola gracias aquí. Ahora seguiré un paso más, la parte de configurar el puerto serie. A pesar que aquí lo indica, quiero hacerlo de otra manera, no de modo automático haciéndonte preguntas cada vez que inicias la aplicación sobre configurar el puerto serie.

Viendo el código base y que está vacío. En este momento quiero centrarme en el menú número 2. Configuración. Donde al pulsar el número 2 pueda configurar el puerto como queramos, los baudios, número del puerto y demás. Por supuesto, al iniciar nuestro programa C#, está configurado de modo predeterminado como cualquier otro programa.



Centrado en este código de abajo, quiero que se muestre los parámetros del puerto serie por defecto y que lo pueda cambiar. Supuestamente pulsado Tabular me cambia de posición en l aventana, pero este caso no lo hace.



Trozo de código que no me sale donde posicionar el cursor para introducir datos.

Código
  1.    class Configuracion
  2.    {
  3.        public void Modal_Configuracion()
  4.        {
  5.            for (; ; )
  6.            {
  7.                Console.Clear();
  8.                Console.WriteLine(@"
  9. &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
  10. &#9474;                               CONFIGURACIÓN                                 &#9474;
  11. &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
  12.  
  13. ");
  14.                //Console.WriteLine("Pulse 0 para vovler al menú principal.");
  15.  
  16.                Console.CursorVisible = true; // Mostrar cursor.
  17.                Console.SetCursorPosition(10, 5); // Pisición del cursor.
  18.                Console.Write("Puerto COM       :");
  19.                Console.SetCursorPosition(10, 6);
  20.                Console.Write("Bits por segundo :");
  21.                Console.SetCursorPosition(10, 7);
  22.                Console.Write("Bits de datos    :");
  23.                Console.SetCursorPosition(10, 8);
  24.                Console.Write("Paridad          :");
  25.                Console.SetCursorPosition(10, 9);
  26.                Console.Write("Bits de parada   :");
  27.                Console.SetCursorPosition(10, 10);
  28.                Console.Write("Control de flujo :");
  29.  
  30.                Console.ReadLine();
  31.  
  32.  
  33.                ConsoleKeyInfo op = Console.ReadKey();
  34.  
  35.                switch (op.KeyChar)
  36.                {
  37.                    case '0':
  38.                        return;
  39.  
  40.                    default:
  41.                        break;
  42.                }
  43.            }
  44.        }
  45.    }

Código Completo de lo que he hecho hasta ahora justo abajo.

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.IO.Ports; // No olvidar.
  8. using System.Threading;
  9.  
  10. namespace PuertoCOM_CS_PRUEBA
  11. {
  12.    class Program
  13.    {
  14.        static void Main(string[] args)
  15.        {
  16.            new Program().Modal();
  17.        }
  18.  
  19.        void Modal()
  20.        {
  21.            for (; ; )
  22.            {
  23.                Console.Title = "Interfaz puerto serie - v 0.03"; // Mostrar título en la ventana de la consola.
  24.  
  25.                string Menu_Principal = @"
  26. &#9556;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9559;
  27. &#9553;                               MENÚ PRINCIPAL                                &#9553;
  28. &#9568;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9571;
  29. &#9553;                                                                             &#9553;
  30. &#9553;                                                                             &#9553;
  31. &#9553;                                                                             &#9553;
  32. &#9553;                                                                             &#9553;
  33. &#9553;                                                                             &#9553;
  34. &#9553;                            0. Salir.                                        &#9553;
  35. &#9553;                            1. Interfaz.                                     &#9553;
  36. &#9553;                            2. Configuración.                                &#9553;
  37. &#9553;                            3. Guardar configuración.                        &#9553;
  38. &#9553;                            4. Información desde el dispositivo.             &#9553;
  39. &#9553;                            5. Ayuda.                                        &#9553;
  40. &#9553;                            6. Acerca de ...                                 &#9553;
  41. &#9553;                                                                             &#9553;
  42. &#9553;                                                                             &#9553;
  43. &#9553;                                                                             &#9553;
  44. &#9553;                                                                             &#9553;
  45. &#9553;                                                                             &#9553;
  46. &#9553;                                                                             &#9553;
  47. &#9553;                                                                             &#9553;
  48. &#9553;                                                                             &#9553;
  49. &#9562;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9552;&#9565;
  50. ";
  51.                Console.CursorVisible = false; // Ocultar cursor.
  52.                Console.Clear(); // Limpiar pantalla.
  53.                Console.Write(Menu_Principal); // Mostrar menú principal.
  54.                ConsoleKeyInfo switchExpression = Console.ReadKey(); // Detactar una tecla del teclado.
  55.  
  56.                switch (switchExpression.KeyChar)
  57.                {
  58.                    case '0':
  59.                        return;
  60.  
  61.                    case '1':
  62.                        new Interfaz().Modal_Interfaz();
  63.                        break;
  64.  
  65.                    case '2':
  66.                        new Configuracion().Modal_Configuracion();
  67.                        break;
  68.  
  69.                    case '3':
  70.                        new Guardar_Configuracion().Modal_Guardar_Configuracion();
  71.                        break;
  72.  
  73.                    case '4':
  74.                        new Informacion().Modal_Informacion();
  75.                        break;
  76.  
  77.                    case '5':
  78.                        new Ayuda().Modal_Ayuda();
  79.                        break;
  80.  
  81.                    case '6':
  82.                        new Acerca_de().Modal_Acerca_de();
  83.                        break;
  84.  
  85.                    default:
  86.                        Console.WriteLine("No has elegido ninguna opción. Vuelva teclear del 0 al 68.");
  87.                        break;
  88.                }
  89.            }
  90.  
  91.        }
  92.    }
  93.  
  94.    class Interfaz
  95.    {
  96.        public void Modal_Interfaz()
  97.        {
  98.            for (; ; )
  99.            {
  100.                Console.Clear();
  101.                Console.WriteLine("===== INTERFAZ =====");
  102.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  103.  
  104.                ConsoleKeyInfo op = Console.ReadKey();
  105.  
  106.                switch (op.KeyChar)
  107.                {
  108.                    case '0':
  109.                        return;
  110.  
  111.                    default:
  112.                        break;
  113.                }
  114.            }
  115.        }
  116.    }
  117.  
  118.    class Configuracion
  119.    {
  120.        public void Modal_Configuracion()
  121.        {
  122.            for (; ; )
  123.            {
  124.                Console.Clear();
  125.                Console.WriteLine(@"
  126. &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
  127. &#9474;                               CONFIGURACIÓN                                 &#9474;
  128. &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
  129.  
  130. ");
  131.                //Console.WriteLine("Pulse 0 para vovler al menú principal.");
  132.  
  133.                Console.CursorVisible = true; // Mostrar cursor.
  134.                Console.SetCursorPosition(10, 5); // Pisición del cursor.
  135.                Console.Write("Puerto COM       :");
  136.                Console.SetCursorPosition(10, 6);
  137.                Console.Write("Bits por segundo :");
  138.                Console.SetCursorPosition(10, 7);
  139.                Console.Write("Bits de datos    :");
  140.                Console.SetCursorPosition(10, 8);
  141.                Console.Write("Paridad          :");
  142.                Console.SetCursorPosition(10, 9);
  143.                Console.Write("Bits de parada   :");
  144.                Console.SetCursorPosition(10, 10);
  145.                Console.Write("Control de flujo :");
  146.  
  147.                Console.ReadLine();
  148.  
  149.  
  150.                ConsoleKeyInfo op = Console.ReadKey();
  151.  
  152.                switch (op.KeyChar)
  153.                {
  154.                    case '0':
  155.                        return;
  156.  
  157.                    default:
  158.                        break;
  159.                }
  160.            }
  161.        }
  162.    }
  163.  
  164.    class Guardar_Configuracion
  165.    {
  166.        public void Modal_Guardar_Configuracion()
  167.        {
  168.            for (; ; )
  169.            {
  170.                Console.Clear();
  171.                Console.WriteLine("===== GUARDAR CONFIGURACIÓN =====");
  172.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  173.  
  174.                ConsoleKeyInfo op = Console.ReadKey();
  175.  
  176.                switch (op.KeyChar)
  177.                {
  178.                    case '0':
  179.                        return;
  180.  
  181.                    default:
  182.                        break;
  183.                }
  184.            }
  185.        }
  186.    }
  187.  
  188.    class Informacion
  189.    {
  190.        public void Modal_Informacion()
  191.        {
  192.            for (; ; )
  193.            {
  194.                Console.Clear();
  195.                Console.WriteLine("===== INFORMACION =====");
  196.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  197.  
  198.                ConsoleKeyInfo op = Console.ReadKey();
  199.  
  200.                switch (op.KeyChar)
  201.                {
  202.                    case '0':
  203.                        return;
  204.  
  205.                    default:
  206.                        break;
  207.                }
  208.            }
  209.        }
  210.    }
  211.  
  212.    class Ayuda
  213.    {
  214.        public void Modal_Ayuda()
  215.        {
  216.            for (; ; )
  217.            {
  218.                Console.Clear();
  219.                Console.WriteLine("===== AYUDA =====");
  220.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  221.  
  222.                ConsoleKeyInfo op = Console.ReadKey();
  223.  
  224.                switch (op.KeyChar)
  225.                {
  226.                    case '0':
  227.                        return;
  228.  
  229.                    default:
  230.                        break;
  231.                }
  232.            }
  233.        }
  234.    }
  235.  
  236.    class Acerca_de
  237.    {
  238.        public void Modal_Acerca_de()
  239.        {
  240.            for (; ; )
  241.            {
  242.                Console.Clear();
  243.                Console.WriteLine("===== ACERCA DE ... =====");
  244.                Console.WriteLine("Pulse 0 para vovler al menú principal.");
  245.  
  246.                ConsoleKeyInfo op = Console.ReadKey();
  247.  
  248.                switch (op.KeyChar)
  249.                {
  250.                    case '0':
  251.                        return;
  252.  
  253.                    default:
  254.                        break;
  255.                }
  256.            }
  257.        }
  258.    }
  259. }
  260.  

Saludos.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines