Esempio n. 1
0
        public void LoadShapes()
        {
            XmlSerializer ser = new XmlSerializer(typeof(GroupsDef));

            using (FileStream fileStream = new FileStream("shapes.xml", FileMode.Open))
            {
                GroupsDef g = (GroupsDef)ser.Deserialize(fileStream);

                int buttonTop = 0;

                for (int x = 0; x < g.Group.Count; x++)
                {
                    GroupDef group = g.Group[x];

                    Button b = new Button();
                    b.Name      = "btnGroup" + group.Name.Trim().Replace(" ", "");
                    b.Text      = group.Name;
                    b.BackColor = Color.White;
                    b.Width     = panel1.Width;
                    b.Top       = buttonTop;
                    b.Height    = 25;
                    b.FlatStyle = FlatStyle.Flat;
                    b.FlatAppearance.BorderColor = Color.Black;
                    b.FlatAppearance.BorderSize  = 1;
                    b.Click   += GroupButton_Click;
                    buttonTop += b.Height + 5;
                    panel1.Controls.Add(b);
                }
            }
        }
Esempio n. 2
0
        private void GroupButton_Click(object sender, EventArgs e)
        {
            int offset = panel1.Height;

            foreach (Control c in panel1.Controls)
            {
                if (c is Panel)
                {
                    c.Controls.Clear();
                    c.Dispose();
                }
            }

            foreach (Control c in panel1.Controls)
            {
                if (c is Button)
                {
                    if (c.Name != ((Button)sender).Name)
                    {
                        // Move unselected group buttons to bottom
                        c.Top  = offset - c.Height;
                        offset = c.Top;
                        c.Tag  = "";
                    }
                    else
                    {
                        // This is the selected group button
                        c.Top = 0;
                        c.Tag = "selected";

                        // Inner panel to contain the shape buttons
                        Panel p = new Panel();
                        p.Width  = panel1.Width;
                        p.Height = panel1.Height;
                        p.Top    = 40;

                        XmlSerializer ser = new XmlSerializer(typeof(GroupsDef));

                        // build the shape buttons and add them to the new inner panel
                        using (FileStream fileStream = new FileStream("shapes.xml", FileMode.Open))
                        {
                            GroupsDef g = (GroupsDef)ser.Deserialize(fileStream);

                            int buttonTop = 0;

                            for (int x = 0; x < g.Group.Count; x++)
                            {
                                if (g.Group[x].Name == c.Text)
                                {
                                    GroupDef group = g.Group[x];

                                    for (int z = 0; z < group.Shape.Count; z++)
                                    {
                                        ShapeDef shapeDefinition = group.Shape[z];

                                        Button b = new Button();
                                        b.Name       = "btnShape" + shapeDefinition.Name.Trim().Replace(" ", "");
                                        b.Text       = shapeDefinition.Name;
                                        b.BackColor  = Color.Beige;
                                        b.Width      = p.Width;
                                        b.Top        = buttonTop;
                                        b.Height     = 35;
                                        b.Tag        = shapeDefinition;
                                        b.MouseDown += ShapeButton_MouseDown;
                                        buttonTop   += b.Height + 5;
                                        p.Controls.Add(b);
                                    }

                                    panel1.Controls.Add(p);
                                }
                            }
                        }
                    }
                }
            }
        }