private void pictureBox6_Click(object sender, EventArgs e) { List <DSClassWrapper> classes = hierarchy_.getClasses(); List <ToolStripMenuItem> items = new List <ToolStripMenuItem>(); foreach (DSClassWrapper cl in classes) { if (check("class", cl.getID())) { ToolStripMenuItem item = new ToolStripMenuItem(cl.getName()); item.Click += new EventHandler(delegate(Object o, EventArgs a) { classifier_.addClass(cl); RefreshParameters(); }); items.Add(item); } } contextMenuStrip1.Items.AddRange(items.ToArray()); Point screenPoint = pictureBox6.PointToScreen(new Point(pictureBox6.Left, pictureBox6.Bottom)); if (screenPoint.Y + contextMenuStrip1.Size.Height > Screen.PrimaryScreen.WorkingArea.Height) { contextMenuStrip1.Show(pictureBox6, new Point(0, -contextMenuStrip1.Size.Height)); } else { contextMenuStrip1.Show(pictureBox6, new Point(0, pictureBox6.Height)); } }