//Loads the states from a previous session into the list of states public void loadStates(List <State> value) { states.Clear(); for (int i = 0; i < value.Count; i++) { //Checks the position of the last control added to see if the maximum number of controls has been reached if (y < 370) { Statepanel panel = new Statepanel(); panel.MouseDown += new MouseEventHandler(panel_RightClick); panel.Location = new Point(x, y); panel.name = value[i].Name; State state = new State(); state.Name = panel.name; states.Add(state); statePanelList.Controls.Add(panel); statePanels.Add(panel); y += 60; } else { return; } } }
//Adds a right click menu to each of the custom controls private void panel_RightClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { contextMenuStrip1.Show(sender as Control, new Point(e.X, e.Y)); StateClicked = sender as Statepanel; } else { return; } }
//Creates a new state and a new custom control to represent that state private void button2_Click(object sender, EventArgs e) { if (y < 370) { Statepanel panel = new Statepanel(); panel.MouseDown += new MouseEventHandler(panel_RightClick); panel.Location = new Point(x, y); panel.name = "New State"; State state = new State(); state.Name = panel.name; states.Add(state); statePanelList.Controls.Add(panel); statePanels.Add(panel); y += 60; } else { return; } }