***UPDATE***
// v1.2
// I've added colors and fonts to the menu items, as well as set a default value.
// There is only one bug with the update at this time;
// I've set it up so that the font size can be changed,
// But at runtime it's not correctly placing the menu entries;
// I will work on it and get the functionality up to speed.
// Anyways, here is the updated source.
// I've included the empty class template for the event args that will handle the navigation of the menu.
// I'm going to go eat and then get back to work. I haven't eaten anything in about 3 days.
// Loss of appitite.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Menu
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Menu myMenu = new Menu(new Point(15, 15));
MenuEntry Entry1 = new MenuEntry("Play", "OCR A Extended", 10f, FontStyle.Regular, GraphicsUnit.Point, Color.Red);
MenuEntry Entry2 = new MenuEntry("Options", "OCR A Extended", 10f, FontStyle.Regular, GraphicsUnit.Point, Color.Blue);
MenuEntry Entry3 = new MenuEntry("Credits", "OCR A Extended", 10f, FontStyle.Regular, GraphicsUnit.Point, Color.Yellow);
MenuEntry Entry4 = new MenuEntry("Exit", "OCR A Extended", 10f, FontStyle.Regular, GraphicsUnit.Point, Color.Lime);
private void Form1_Load(object sender, EventArgs e)
{
myMenu.NewMenuItem(Entry1);
myMenu.NewMenuItem(Entry2);
myMenu.NewMenuItem(Entry3);
myMenu.NewMenuItem(Entry4);
for (int i = 0; i < myMenu.SelectedIndex; i++)
this.Controls.Add(myMenu.Items[i]);
}
}
public class MenuEntry
{
public string Text;
public Point Location;
public Color Color = Color.Black;
public Font Font = new Font("OCR A Extended", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
public MenuEntry(string Text, string FontName, float FontSize, FontStyle Style, GraphicsUnit GraphicsUnit, Color Color)
{
this.Text = Text;
this.Font = new Font(FontName, FontSize, Style, GraphicsUnit, ((byte)(0)));
this.Color = Color;
}
}
public class Menu
{
private List<MenuEntry> MenuItems;
public Point Location { get; private set; }
public int SelectedIndex { get; private set; }
public List<Label> Items { get; private set; }
public int SelectedItem { get; private set; }
public Menu(Point Location)
{
MenuItems = new List<MenuEntry>();
Items = new List<Label>();
this.Location = Location;
}
public void NewMenuItem(MenuEntry Entry)
{
MenuItems.Add(Entry);
Items.Add(new Label());
if (this.SelectedIndex == 0)
MenuItems[SelectedIndex].Location = this.Location;
else
MenuItems[SelectedIndex].Location = new Point(this.Location.X, MenuItems[SelectedIndex - 1].Location.Y + Items[SelectedIndex].Size.Height);
Items[SelectedIndex].Text = Entry.Text;
Items[SelectedIndex].Location = MenuItems[SelectedIndex].Location;
Items[SelectedIndex].Font = Entry.Font;
Items[SelectedIndex].ForeColor = Entry.Color;
Items[SelectedIndex].BackColor = Color.Transparent;
SelectedIndex++;
}
}
public class Dev9MenuIndexChanged : EventArgs
{
}
}