c# console application menu system

// This is a Visual Studio Console application.
// How to create a menu system!
// Make sure your using:
using System.Collections.Generic;

// Copy this into a class:
static int indexMainMenu = 0;

public static void mainMenu()
{
	Console.Clear();

	List<string> menuItems = new List<string>()
	{
    	"Play",
        "Settings",
        "Exit"
	};

    Console.CursorVisible = false;
    while (true)
    {
    	string selectedMenuItem = drawMainMenu(menuItems);
        if (selectedMenuItem == "Play")
		{
        	// Play the game, or start the app
		}
        else if (selectedMenuItem == "Settings")
        {
        	/* Go to settings. Call a method, in the method just
            copy this menu system and change the list names for
            each setting you want.*/
		}
        else if (selectedMenuItem == "Exit")
        {
        	Environment.Exit(0); // Or  System.Environment.Exit(0);
        }
	}
}

public static string drawMainMenu(List<string> items)
{
	for (int i = 0; i < items.Count; i++)
    {
    	if (i == indexMainMenu)
        {
        	Console.BackgroundColor = ConsoleColor.Gray;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WriteLine(items[i]);
        }
        else
        {
        	Console.WriteLine(items[i]);
        }
        Console.ResetColor();
	}

    ConsoleKeyInfo ckey = Console.ReadKey();
    if (ckey.Key == ConsoleKey.DownArrow)
    {
		if (indexMainMenu == items.Count - 1) { }
        else { indexMainMenu++; }
	}
    else if (ckey.Key == ConsoleKey.UpArrow)
    {
    	if (indexMainMenu <= 0) { }
        else { indexMainMenu--; }
    }
    else if (ckey.Key == ConsoleKey.LeftArrow)
    {
        Console.Clear();
    }
    else if (ckey.Key == ConsoleKey.RightArrow)
    {
		Console.Clear();
    }
    else if (ckey.Key == ConsoleKey.Enter)
    {
		return items[indexMainMenu];
    }
    else
    {
		return "";
    }

	Console.Clear();
    return "";
}

// wow you scrolled this far...

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c# console menu f c# console menu options console menu c# create menu console application c# create a menu in console c# menu console c# C# console menu coding console menu ui c# creating menu system in c# console c# console application menu and submenu c# menu example for console window console application menu c# C# console application menu example c# console menu library c# console app menu options how to make a menu in console c# Creating a admin menu using console app c# user input menus examples C# simple menu in c# console application tutorial c# console simple menu c# console application main menu menu for console c# create a menu in c# console application display a menu in c# console application Add options to the main menu C# console app manu c sharp console menu yazmak menu c# console c sharp console menu c sharp console de menu yazmak c# Menu in console menu c sharp console kode c# console menu loop create a console menu c# creating menu in c# console application c# consol aplication advanced menu c# create menu in console main menu c# code basic menu c# how to make menu in c# console c# console applications menu design c# console applications menu template c# .net console menu c# menu in console application console application menu C# code menu with read key console C# responsive menu how to make a navigation bar in a console app c# .MenuInput() c# c# console game menu how o i make asselection for meny on console program in c# c# console option menu how to create a menu in c# console application console options c# menu selection methods c# C# console app easy menu c# menu console creating a console menu in c# C# console app selection menu how to show menu again c# c# cconsole menu create option menu c# c# console menu example create a choice console in c# c# console application menu c# console menu oop list menu in c# console application how to make a menu in c# console application c# console menu system c# console application menu system
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source