Example #1
0
        private void ToolBoxSelect()
        {
            _toolboxService = new CustomToolboxService();
            // 选中不同的工具条项目
            m_toolbox.toolBox.SelectedItemChanged += delegate(object sender, ToolBoxItem newItem)
            {
                _toolboxService.SetSelectedToolboxItem(newItem.Tag as System.Drawing.Design.ToolboxItem);
            };

            // 双击工具栏项目时增加到设计器中
            m_toolbox.toolBox.ItemDoubleClicked += delegate(object sender, ToolBoxItem newItem)
            {
                System.Drawing.Design.ToolboxItem toolboxItem = newItem.Tag as System.Drawing.Design.ToolboxItem;
                if (null != toolboxItem && ActivPage.surFace != null)
                {
                    IToolboxUser toolboxUser = ActivPage.host.GetDesigner(ActivPage.host.RootComponent as IComponent) as IToolboxUser;
                    if (null != toolboxUser)
                    {
                        toolboxUser.ToolPicked(toolboxItem);
                    }
                }
            };

            // 拖动工具栏项目的支持代码
            m_toolbox.toolBox.ItemDragStart += delegate(object sender, ToolBoxItem newItem)
            {
                System.Drawing.Design.ToolboxItem toolboxItem = newItem.Tag as System.Drawing.Design.ToolboxItem;
                if (null != toolboxItem)
                {
                    DataObject dataObject = ((IToolboxService)_toolboxService).SerializeToolboxItem(toolboxItem) as DataObject;
                    m_toolbox.toolBox.DoDragDrop(dataObject, DragDropEffects.Copy);
                }
            };
            _toolboxService.ResetToolboxItem += delegate
            {
                m_toolbox.toolBox.ResetSelection();
            };
        }
Example #2
0
        internal Guid pageGuid;//与model的编号对应



        public DesignWorkbench(string pageName)
        {
            InitializeComponent();
            AutoScaleMode = AutoScaleMode.Dpi;

            PageMoel pm = new PageMoel();

            _propertyGrid = new PropertyGrid {
                Dock = DockStyle.Fill
            };
            pm.propertyGrid = _propertyGrid;
            pm.PageName     = pageName;

            ServiceContainer serviceContainer = new ServiceContainer();

            serviceContainer.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService());
            serviceContainer.AddService(typeof(System.ComponentModel.Design.Serialization.INameCreationService), new NameCreationService());
            _toolboxService = new CustomToolboxService();
            serviceContainer.AddService(typeof(IToolboxService), _toolboxService);

            surface = new DesignSurface(serviceContainer);
            _host   = (IDesignerHost)surface.GetService(typeof(IDesignerHost));

            serviceContainer.AddService(typeof(System.ComponentModel.Design.IEventBindingService), new Services.EventBindingService(surface));

            _menuCommandService = new MenuCommandService(surface);
            serviceContainer.AddService(typeof(IMenuCommandService), _menuCommandService);

            //surface.BeginLoad(typeof(Form));
            _CodeDomHostLoader = new Loader.CodeDomHostLoader();
            surface.BeginLoad(_CodeDomHostLoader);

            Control designerContorl = (Control)surface.View;


            designerContorl.BackColor = Color.Aqua;
            designerContorl.Dock      = DockStyle.Fill;
            //获取root组件
            var designerHost = (IDesignerHost)this._host;

            if (designerHost != null)
            {
                rootComponent = (Form)designerHost.RootComponent;
            }

            rootComponent.FormBorderStyle = FormBorderStyle.None;

            #region 初始化窗体大小

            //- set the Size
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(designerContorl);
            //- Sets a PropertyDescriptor to the specific property.
            PropertyDescriptor pdS = pdc.Find("Size", false);
            if (null != pdS)
            {
                pdS.SetValue(_host.RootComponent, new Size(800, 480));
            }
            #endregion
            tpDesign.Controls.Add(designerContorl);//窗体

            _textEditor = new TextEditorControl
            {
                IsReadOnly = true,
                Dock       = DockStyle.Fill,
                Document   = { HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("C#") }
            }; //代码编辑器
            tpCode.Controls.Add(_textEditor);

            _propertyGrid.SelectedObject = surface.ComponentContainer.Components[0];
            _propertyGrid.Site           = (new IDEContainer(_host)).CreateSite(_propertyGrid);
            _propertyGrid.PropertyTabs.AddTabType(typeof(System.Windows.Forms.Design.EventsTab), PropertyTabScope.Document);


            pm.serviceContainer = serviceContainer;
            pm.surFace          = surface;
            pageGuid            = Guid.NewGuid();
            pm.PageGuid         = pageGuid;
            List <PageMoel> pages = GolableInstance.PageList();
            pages.Add(pm);


            //if (ChangeSur != null) ChangeSur();
        }