Пример #1
0
        /*
         * 通过XML文件来加载页面控件对象
         *
         * xml - 一个页面对应的xml对象
         * isCreate - true: 创建新的ID号
         *            false: 直接使用文件中的ID号
         * */
        public void loadXML(SVXml xml, Boolean isCreate = false)
        {
            _redoUndo.setEnabled(false);

            XmlElement page = xml.CurrentElement;

            if (isCreate)
            {
                var instance = SVUniqueID.instance();
                _attrib.id = instance.newUniqueID();
                instance.saveFile();
            }
            else
            {
                _attrib.id = UInt16.Parse(page.GetAttribute("ID"));
            }

            try
            {
                XmlElement width = xml.select("Width");
                _attrib.Width = int.Parse(width.InnerText);

                XmlElement height = xml.select("Height");
                _attrib.Height = int.Parse(height.InnerText);

                XmlElement back = xml.select("Backcolor");
                _attrib.BackColor = Color.FromArgb(int.Parse(back.InnerText));

                XmlElement mainPage = xml.select("MainPage");
                _attrib.IsMainPage = Boolean.Parse(mainPage.InnerText);
                if (_attrib.IsMainPage)
                {
                    setToMainPageWidget();
                }

                XmlElement backGroundType = xml.select("BackGroundType");
                _attrib.BackGroundType = Byte.Parse(backGroundType.InnerText);

                XmlElement picShowName = xml.select("PicShowName");
                _attrib.PicIconData.ShowName = picShowName.InnerText;

                XmlElement picFile = xml.select("PicFile");
                _attrib.PicIconData.ImageFileName = picFile.InnerText;


                XmlElement alignMent = xml.select("alignment");
                _attrib.IsAlignment = Byte.Parse(alignMent.InnerText);
            }
            catch (Exception)
            {
            }

            //读取当前页面的所有子控件
            List <XmlElement> listNodes = xml.selectChilds();

            foreach (XmlElement node in listNodes)
            {
                SVPanel svPanel = SVNameToObject.getInstance(node.Name) as SVPanel;
                if (svPanel == null)
                {
                    continue;
                }

                svPanel.setRedoUndoObject(_redoUndo);
                svPanel.setParentID(_attrib.id);

                svPanel.MouseDown += new MouseEventHandler((sder, ev) =>
                {
                    MouseSelectEvent(sder, ev);
                });

                svPanel.MouseUp += new MouseEventHandler((sder, ev) =>
                {
                    MouseSelectEvent(sder, ev);
                });

                this.Controls.Add(svPanel);
                xml.CurrentElement = node;
                svPanel.loadXML(xml, isCreate);
                svPanel.refreshPropertyToPanel();
            }

            _redoUndo.setEnabled(true);
        }
Пример #2
0
        /// <summary>
        /// 控件拖入页面窗口中的事件操作
        /// </summary>
        /// <param Name="e"></param>
        protected override void OnDragDrop(DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(SVSelectItem)))
            {
                return;
            }

            ///禁用记录
            _redoUndo.setEnabled(false);

            SVSelectItem item = (SVSelectItem)e.Data.GetData(typeof(SVSelectItem));
            SVPanel      btn  = (SVPanel)(item._obj);

            btn.setRedoUndoObject(_redoUndo);
            btn.setParentID(Attrib.id);
            btn.refreshPropertyToPanel();

            btn.Location = this.PointToClient(new Point(e.X, e.Y));
            btn.Location = new Point(btn.Location.X - btn.Width / 2, btn.Location.Y - btn.Height / 2);
            btn.setStartPos(btn.Location);

            this.Controls.Add(btn);
            btn.newID();
            ChildAddEvent(btn, null);

            btn.MouseDown += new MouseEventHandler((sder, ev) =>
            {
                MouseSelectEvent(sder, ev);
            });

            btn.MouseUp += new MouseEventHandler((sder, ev) =>
            {
                MouseSelectEvent(sder, ev);
            });


            ///启用记录
            _redoUndo.setEnabled(true);

            ///记录重做操作
            ///这里只记录控件的添加和删除操作,其他属性的改变并不会被记录下来。
            SVRedoUndoItem recordItem = new SVRedoUndoItem();

            recordItem.ReDo = () =>
            {
                _redoUndo.setEnabled(false);
                btn.Selected = false;
                this.Controls.Add(btn);
                _redoUndo.setEnabled(true);
            };
            recordItem.UnDo = () =>
            {
                _redoUndo.setEnabled(false);
                btn.Selected = false;
                this.Controls.Remove(btn);
                _redoUndo.setEnabled(true);
            };

            ///执行记录
            _redoUndo.recordOper(recordItem);
        }