0% found this document useful (0 votes)
62 views1 page

Read Key

This document contains code to create a console window with a random welcome message and prompt the user to press 1 or 2. It sets the console title, background color, foreground color, cursor position, and writes text. It uses a random number generator to position the welcome text randomly. It then waits for the user to press 1 or 2 before displaying a message at the bottom to press a key to exit.

Uploaded by

Marvin Caniz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views1 page

Read Key

This document contains code to create a console window with a random welcome message and prompt the user to press 1 or 2. It sets the console title, background color, foreground color, cursor position, and writes text. It uses a random number generator to position the welcome text randomly. It then waits for the user to press 1 or 2 before displaying a message at the bottom to press a key to exit.

Uploaded by

Marvin Caniz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

int posX, posY; Console.Title = "Ejemplo de consola"; Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Black; Console.

Clear(); posY = 10; // En la fila 10 Random r = new Random(DateTime.Now.Millisecond); posX = r.Next(20, 40); // Columna al azar entre 20 y 40 Console.SetCursorPosition(posX, posY); Console.WriteLine("Bienvenido"); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(10, 15); Console.Write("Pulsa 1 o 2: "); ConsoleKeyInfo tecla; do { tecla = Console.ReadKey(false); } while ((tecla.KeyChar != '1') && (tecla.KeyChar != '2')); int maxY = Console.WindowHeight; int maxX = Console.WindowWidth; Console.SetCursorPosition(maxX - 50, maxY - 1); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Pulsa una tecla para terminar... "); Console.ReadKey(false);

You might also like