M
Metaconta
Guest
Hello:
I want to adapt or transform from C# code to F#.
Code C#:
Thank you.
Continue reading...
I want to adapt or transform from C# code to F#.
Code C#:
C#:
using System;
namespace radioButton_consola_02_cs
{
class Program
{
#region Variables.
private static readonly string[] TEXTO = new string[]
{
"( ) Option A ",
"( ) Option B ",
"( ) Option C ",
" EXIT"
};
private static int itemSeñalado;
private static int itemSeleccionado;
#endregion
static void Main(string[] args)
{
// Window title.
Console.Title = "RadioButton";
// Window size.
Console.SetWindowSize(20, 5);
// Green background.
Console.BackgroundColor = ConsoleColor.Blue;
// Black letters.
Console.ForegroundColor = ConsoleColor.White;
// I hide the cursor.
Console.CursorVisible = false;
// Stores the key pressed in the variable.
ConsoleKey teclaInicial;
do
{
// Clean screen.
Console.Clear();
// Cursor position of the MAIN MENU title.
Console.SetCursorPosition(0, 0);
// Title.
Console.Write(" MENÚ PRINCIPAL ");
// Time position.
Console.SetCursorPosition(4, 2);
// Numeric format dd/MM/yyyy.
Console.Write(DateTime.Now.ToString("ddd dd MMM"));
// Stores a pressed key in the variable.
teclaInicial = Console.ReadKey(true).Key;
// Did you press the Enter key?
if (teclaInicial == ConsoleKey.Enter)
{
// Yes. This function is executed.
MenuPrincipal();
}
} while (teclaInicial != ConsoleKey.Escape);
}
#region Main menu.
private static void MenuPrincipal()
{
bool salir = false;
// In itemSelecionado:
// -1 = Not selected with * any option.
// 0 = Select with * Option A.
// 1 = Select with * Option B.
// 2 = Select with * Option C.
// Capture key and then validate.
ConsoleKey tecla;
// Every time you return to the menu, it is marked with the *.
itemSeñalado = 0;
do
{
//******************************************************************
// I draw the main menu.
// Clean screen.
Console.Clear();
for (int k = 0; k < TEXTO.Length; k++)
{
Console.SetCursorPosition(0, k);
Console.Write(itemSeñalado == k ? "> " : " ");
Console.Write(TEXTO[k]);
Console.SetCursorPosition(3, k);
Console.Write(itemSeleccionado == k ? "*" : " ");
}
// End of painting the main menu.
//******************************************************************
// Read key entered by user.
tecla = Console.ReadKey(true).Key;
switch (tecla)
{
case ConsoleKey.Enter:
if (itemSeñalado < 3)
{
itemSeleccionado = itemSeñalado;
}
salir = (itemSeñalado == TEXTO.Length - 1);
break;
case ConsoleKey.DownArrow:
if (++itemSeñalado >= TEXTO.Length)
{
itemSeñalado = 0;
}
break;
case ConsoleKey.UpArrow:
if (--itemSeñalado < 0)
{
itemSeñalado = TEXTO.Length - 1;
}
break;
}
// I use the escape key as output.
} while (!salir);
}
#endregion
}
}
Continue reading...
Last edited by a moderator: