示例#1
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);
        }
示例#2
0
        //初始化要创建控件的对应关系
        void initControl()
        {
            ResourceManager r = new ResourceManager(typeof(Resource));
            ///显示项
            ListViewItem buttonItem    = this.Items.Add(r.GetString("按钮"));
            ListViewItem textItem      = this.Items.Add(r.GetString("文本"));
            ListViewItem iconItem      = this.Items.Add(r.GetString("图标"));
            ListViewItem gifItem       = this.Items.Add(r.GetString("动态图"));
            ListViewItem vLineItem     = this.Items.Add(r.GetString("水平线条"));
            ListViewItem hLineItem     = this.Items.Add(r.GetString("垂直线条"));
            ListViewItem curvesItem    = this.Items.Add(r.GetString("曲线图"));
            ListViewItem analogItem    = this.Items.Add(r.GetString("模拟量"));
            ListViewItem binaryItem    = this.Items.Add(r.GetString("开关量"));
            ListViewItem heartBeatItem = this.Items.Add(r.GetString("心跳控件"));

            ///设置图片
            this.View           = System.Windows.Forms.View.LargeIcon;
            this.LargeImageList = new ImageList();
            LargeImageList.Images.Add("AreaText", Resource.Text);
            LargeImageList.Images.Add("Button", Resource.button);
            LargeImageList.Images.Add("gif", Resource.gif);
            LargeImageList.Images.Add("Trendchart", Resource.Trendchart);
            LargeImageList.Images.Add("analog", Resource.analog);
            LargeImageList.Images.Add("binary", Resource.binary);
            LargeImageList.Images.Add("line", Resource.line);
            LargeImageList.Images.Add("ico", Resource.ico);
            LargeImageList.Images.Add("hline", Resource.hline);
            LargeImageList.Images.Add("tick", Resource.tick);
            this.LargeImageList.ImageSize = new Size(80, 40);// 设置行高 20 //分别是宽和高

            ///设置图片
            buttonItem.ImageKey    = "Button";
            textItem.ImageKey      = "AreaText";
            iconItem.ImageKey      = "ico";
            curvesItem.ImageKey    = "Trendchart";
            gifItem.ImageKey       = "gif";
            analogItem.ImageKey    = "analog";
            binaryItem.ImageKey    = "binary";
            vLineItem.ImageKey     = "line";
            hLineItem.ImageKey     = "hline";
            heartBeatItem.ImageKey = "tick";

            //线条
            _funcDict.Add(vLineItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVLine());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            _funcDict.Add(hLineItem.Index, () =>
            {
                SVSelectItem item    = new SVSelectItem();
                SVLine line          = new SVLine();
                line.Attrib.ShowType = false;
                item._obj            = (object)(line);
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });


            //创建按钮
            _funcDict.Add(buttonItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVButton());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //创建文本
            _funcDict.Add(textItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVLabel());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //创建图标
            _funcDict.Add(iconItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVIcon());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //创建动态图
            _funcDict.Add(gifItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVGif());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //趋势图
            _funcDict.Add(curvesItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVCurve());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //模拟量显示
            _funcDict.Add(analogItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVAnalog());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //开关量显示
            _funcDict.Add(binaryItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVBinary());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //心跳显示
            _funcDict.Add(heartBeatItem.Index, () =>
            {
                SVSelectItem item = new SVSelectItem();
                item._obj         = (object)(new SVHeartbeat());
                this.DoDragDrop(item, DragDropEffects.Copy | DragDropEffects.Move);
            });

            //执行事件
            this.ItemDrag += new ItemDragEventHandler(slotItemDrag);
        }