This article has been dead for over three months
You
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");
MenuEntry Entry2 = new MenuEntry("Options");
MenuEntry Entry3 = new MenuEntry("Credits");
MenuEntry Entry4 = new MenuEntry("Exit");
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 MenuEntry(string Text)
{
this.Text = Text;
}
}
public class Menu
{
public List<MenuEntry> MenuItems;
public Point Location;
public int SelectedIndex = 0;
public List<Label> Items;
public Menu(Point Location)
{
MenuItems = new List<MenuEntry>();
Items = new List<Label>();
this.Location = Location;
}
public void NewMenuItem(MenuEntry Entry)
{
MenuItems.Add(new MenuEntry(Entry.Text));
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;
SelectedIndex++;
}
}
}