Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Question about add group and ungroup to the Editor Sample.

Last post 11-12-2007 5:36 PM by James Westgate. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 11-12-2007 2:40 AM

    Question about add group and ungroup to the Editor Sample.

    Hello , I try to add some function to the Editor Sample.

    It is more like the visio's group and ungroup.

    Do I missing something...

    Here is my code.

            private void button3_Click(object sender, EventArgs e)
            {
                //Ungroup
                frmDiagram active = (frmDiagram)this.ActiveMdiChild;

                active.Model.Suspend();


                if (active.Model.SelectedShapes().Count == 1)
                {
                    foreach (Shape s in active.Model.SelectedShapes().Values)
                    {


                        if (s is Group)
                        {
                            Group group = s as Group;

                            List<Shape> sl = new List<Shape>();
                            foreach (Shape gs in group.Shapes.Values)
                            {
                                sl.Add(gs);
                            }
                            foreach (Shape gs in sl)
                            {

                                group.Shapes.Remove(gs.Key);

                                gs.AllowMove = true;
                                gs.DrawSelected = true;
                             //   active.Model.Shapes.Add(gs.Key, gs); // It is always error here.
                            }

                            List<Line> ll = new List<Line>();
                            foreach (Line gl in group.Lines.Values)
                            {
                                ll.Add(gl);
                            }
                            foreach (Line gl in ll)
                            {

                                group.Lines.Remove(gl.Key);
                                gl.AllowMove = true;
                                gl.DrawSelected = true;
                             //   active.Model.Lines.Add(gl.Key, gl);
                            }


                            active.Model.Shapes.Remove(s.Key);
                        }

                    }
                }
                active.Model.Resume();
                active.Model.Invalidate();
            }

            private void button2_Click(object sender, EventArgs e)
            {
                //group
                frmDiagram active = (frmDiagram)this.ActiveMdiChild;


                float ltx = float.MaxValue;
                float lty = float.MaxValue;
                float rbx = float.MinValue;
                float rby = float.MinValue;

                active.Model.Suspend();

                Group group = active.Model.Runtime.CreateGroup();
                foreach (Element et in active.Model.SelectedElements().Values)
                {

                    //if (et.X < ltx) ltx = et.X;
                    //if (et.Y < lty) lty = et.Y;
                    //if (et.X + et.Width > rbx) rbx = et.X + et.Width;
                    //if (et.Y + et.Height < rby) rby = et.X + et.Height;


                    if (et is Shape)
                    {
                        active.Model.Shapes.Remove(et.Key);
                        (et as Shape).AllowMove = false;
                        (et as Shape).DrawSelected = false;

                        group.Shapes.Add(et.Key, et);
                    }
                    else
                        if (et is Line)
                        {
                            active.Model.Lines.Remove(et.Key);
                            (et as Line).AllowMove = false;
                            (et as Line).DrawSelected = false;
                            group.Lines.Add(et.Key, et);
                        }

                }
                active.Model.Shapes.Add("Group_" + active.Model.Shapes.CreateKey(), group);
                active.Model.Resume();
                active.Model.Invalidate();

            }
     

     

    • 211.72.233.8
  • 11-12-2007 5:36 PM In reply to

    Re: Question about add group and ungroup to the Editor Sample.

    A group is like a container, containing seperate elements within it. I would suggest trying the same code, but using a ComplexShape element instead.

     

    Filed under:
    • 81.132.167.65
Page 1 of 1 (2 items)