コード例 #1
0
ファイル: VisualGraph.cs プロジェクト: sjyfok/cpp
        //将所选工具加入到页面容器中
        private void VisualGraph_DragDrop(object sender, DragEventArgs e)
        {
            Point point = new Point(e.X, e.Y);

            point = this.PointToClient(point);
            switch (activedObjType)
            {
            case Global.DrawType.DrawText:
                DrawText text = new DrawText(point, this);
                objList.UnselectAll();
                objList.AddObject(text);
                text.Selected = true;
                break;

            case Global.DrawType.DrawRectangle:
                DrawRectangle rect = new DrawRectangle(point, this);
                objList.UnselectAll();
                objList.AddObject(rect);
                rect.Selected = true;
                break;

            case Global.DrawType.DrawEllipse:
                DrawEllipse elip = new DrawEllipse(point, this);
                objList.UnselectAll();
                objList.AddObject(elip);
                elip.Selected = true;
                break;

            case Global.DrawType.DrawLine:
                DrawLine line = new DrawLine(point, this);
                objList.UnselectAll();
                objList.AddObject(line);
                line.Selected = true;
                break;

            case Global.DrawType.DrawPic:
                DrawPic pic = new DrawPic(point, this);
                objList.UnselectAll();
                objList.AddObject(pic);
                pic.Selected = true;
                break;
            }
            activedObjType = Global.DrawType.POINTER;
            this.Refresh();
        }
コード例 #2
0
        public void LoadFromXml(string file)
        {
            XmlDocument   xdoc = new XmlDocument();
            XmlTextReader xtr  = new XmlTextReader(file);

            xdoc.Load(xtr);
            int n = xdoc.DocumentElement.ChildNodes.Count;

            for (int i = 0; i < n; i++)
            {
                XmlElement xe             = (XmlElement)xdoc.DocumentElement.ChildNodes[i];
                string     drawObjectType = xe.GetAttribute("Type");
                if (drawObjectType.Equals("VisualGraph"))
                {
                    DocFromXml(xe);
                }
                else
                {
                    DrawObject drawObject = null;
                    switch (drawObjectType)
                    {
                    case "DrawEllipse":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawEllipse));
                        break;

                    case "DrawLine":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawLine));
                        break;

                    case "DrawPic":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawPic));
                        break;

                    case "DrawRectangle":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawRectangle));
                        break;

                    case "DrawText":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawText));
                        break;
                    }
                    drawObject.ReadFromXml(xe);
                    ObjList.AddObject(drawObject);
                }
            }
        }
        public void LoadFromXml(string file)
        {
            XmlDocument   xdoc = new XmlDocument();
            XmlTextReader xtr  = new XmlTextReader(file);

            xdoc.Load(xtr);
            int n = xdoc.DocumentElement.ChildNodes.Count;

            for (int i = 0; i < n; i++)
            {
                XmlElement xe             = (XmlElement)xdoc.DocumentElement.ChildNodes[i];
                string     drawObjectType = xe.GetAttribute("Type");
                if (drawObjectType.Equals("VisualGraph"))
                {
                    DocFromXml(xe);
                }
                else
                {
                    DrawObject drawObject = (DrawObject)Activator.CreateInstance("VisualGraph", "VisualGraph." + drawObjectType).Unwrap();
                    drawObject.ReadFromXml(xe);
                    ObjList.AddObject(drawObject);
                }
            }
        }