Sign in to follow this  
  • entries
    3
  • comments
    2
  • views
    3153

Highlight Menu

Sign in to follow this  
brandogon

302 views



I created this menu as a personal exercise to dive into C# a little farther during the first two weeks of the workshop. I hope to be able to use this somewhere in the text game we'll be working on. I've always liked these types of menus.

Some features:
- Text alignment (Left, Center, Right) within the highlighted area
- Add/Remove any object to/from the menu
- Console Colors
- Menu X, Y placement
- Other misc stuff

The testing code:

using System;
using MenuSelection;

class TestMenuSelection
{
static void Main(string[] args)
{
int fieldWidth = 25;
int numOptions = 5;

MenuColors menuColors = new MenuColors();
menuColors.SelectionBackgroundColor = ConsoleColor.Blue;
menuColors.SelectionForegroundColor = ConsoleColor.White;

VerticalMenuBar mainMenu = new VerticalMenuBar(fieldWidth, menuColors, TextAlignment.CENTER);
mainMenu.MenuWrapAround = true;

for (int i = 0; i < numOptions; i++)
mainMenu.AddOption("Option " + (i + 1));
mainMenu.AddOption("Quit");

mainMenu.X = (Console.WindowWidth - fieldWidth) / 2; // center
mainMenu.Y = (Console.WindowHeight - numOptions) / 2; // center

string opt;
do
{
Console.Clear();
opt = mainMenu.DoMenu().ToString();
Console.WriteLine("\nYou selected {0}.\nSlap a key to continue.", opt);
Console.ReadKey(true);
} while (opt != "Quit");
}
}






I'll post the source to the rest later after I add a horizontal menu class and clean it up. [smile]

One thing that is missing is quick-key selection, such as pressing F1 or ESC to select an option. I may or may not add that feature. I really don't have any idea yet how I would implement that. I'm sure something in the next few weeks of the workshop will help.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now