Example #1
0
 public static void LoadToolbox()
 {
     if (!componentLibraryLoader.LoadToolComponentLibrary(UserConfigFile))
     {
         if (!componentLibraryLoader.LoadToolComponentLibrary(GlobalConfigFile))
         {
             MessageService.ShowWarning("${res:ICSharpCode.SharpDevelop.FormDesigner.ToolboxProvider.CantLoadSidbarComponentLibraryWarning}");
         }
     }
 }
Example #2
0
        public DummyToolbox()
        {
            InitializeComponent();

            #region Ìí¼ÓToolBox

            string fileName = Application.StartupPath + @"\..\..\data\ControlLibrary.xml";
            ComponentLibraryLoader componentLibraryLoader = new ComponentLibraryLoader();
            componentLibraryLoader.LoadToolComponentLibrary(fileName);

            toolBox = new ToolBox.ToolBox {
                Dock = DockStyle.Fill
            };

            foreach (Category category in componentLibraryLoader.Categories)
            {
                if (category.IsEnabled)
                {
                    ToolBoxCategory cate = new ToolBoxCategory();
                    cate.ImageIndex = -1;
                    cate.IsOpen     = false;
                    cate.Name       = category.Name;
                    cate.Parent     = null;

                    ToolBoxItem item = new ToolBoxItem();
                    item.Tag    = null;
                    item.Name   = "<Pointer>";
                    item.Parent = null;
                    cate.Items.Add(item);

                    foreach (ToolComponent component in category.ToolComponents)
                    {
                        item = new ToolBoxItem();

                        System.Drawing.Design.ToolboxItem toolboxItem = new System.Drawing.Design.ToolboxItem();
                        toolboxItem.TypeName    = component.FullName;
                        toolboxItem.Bitmap      = componentLibraryLoader.GetIcon(component);
                        toolboxItem.DisplayName = component.Name;
                        Assembly asm = component.LoadAssembly();
                        toolboxItem.AssemblyName = asm.GetName();

                        item.Image  = toolboxItem.Bitmap;
                        item.Tag    = toolboxItem;
                        item.Name   = component.Name;
                        item.Parent = null;

                        cate.Items.Add(item);
                    }

                    toolBox.Categories.Add(cate);
                }
            }

            pnlToolBox.Controls.Add(toolBox);//×ó±ßpanelÌí¼Ó¿Ø¼þ

            #endregion
        }
Example #3
0
 public static void LoadToolbox()
 {        //roman//
     {
         string componentsLibraryPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "ControlLibrary.sdcl");
         if (!componentLibraryLoader.LoadToolComponentLibrary(componentsLibraryPath))
         {
             System.Windows.Forms.MessageBox.Show(PascalABCCompiler.StringResources.Get("VP_MF_TOOLBOX_LOADING_UNSUCCEFULL"),
                                                  PascalABCCompiler.StringResources.Get("VP_MF_FORM_DESIGNER"),
                                                  System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         }
     }
 }
Example #4
0
        /// <summary>
        /// Creates a new instance of the SetupDialogControlsSideTab class.
        /// </summary>
        public static SetupDialogControlsSideTab CreateSideTab()
        {
            ComponentLibraryLoader loader = new ComponentLibraryLoader();

            loader.LoadToolComponentLibrary(ToolComponentLibraryFileName);

            // Fix WixBinding assembly hint path.
            Category category = (Category)loader.Categories[0];

            foreach (ToolComponent toolComponent in category.ToolComponents)
            {
                toolComponent.HintPath = StringParser.Parse(toolComponent.HintPath);
            }
            return(new SetupDialogControlsSideTab(WixDialogDesigner.SetupDialogControlsToolBox, category, ToolboxProvider.ToolboxService));
        }
        /// <summary>
        /// 窗体初始化
        /// </summary>
        void CustomInitialize()
        {
            #region 添加ToolBox

            string fileName = Application.StartupPath + @"\..\data\SharpDevelopControlLibrary.xml";
            ComponentLibraryLoader componentLibraryLoader = new ComponentLibraryLoader();
            componentLibraryLoader.LoadToolComponentLibrary(fileName);

            Guanjinke.Windows.Forms.ToolBox toolBox = new Guanjinke.Windows.Forms.ToolBox {
                Dock = DockStyle.Fill
            };

            foreach (Category category in componentLibraryLoader.Categories)
            {
                if (category.IsEnabled)
                {
                    Guanjinke.Windows.Forms.ToolBoxCategory cate = new Guanjinke.Windows.Forms.ToolBoxCategory();
                    cate.ImageIndex = -1;
                    cate.IsOpen     = false;
                    cate.Name       = category.Name;
                    cate.Parent     = null;

                    Guanjinke.Windows.Forms.ToolBoxItem item = new Guanjinke.Windows.Forms.ToolBoxItem();
                    item.Tag    = null;
                    item.Name   = "<Pointer>";
                    item.Parent = null;
                    cate.Items.Add(item);

                    foreach (ToolComponent component in category.ToolComponents)
                    {
                        item = new Guanjinke.Windows.Forms.ToolBoxItem();

                        System.Drawing.Design.ToolboxItem toolboxItem = new System.Drawing.Design.ToolboxItem();
                        toolboxItem.TypeName    = component.FullName;
                        toolboxItem.Bitmap      = componentLibraryLoader.GetIcon(component);
                        toolboxItem.DisplayName = component.Name;
                        Assembly asm = component.LoadAssembly();
                        toolboxItem.AssemblyName = asm.GetName();

                        item.Image  = toolboxItem.Bitmap;
                        item.Tag    = toolboxItem;
                        item.Name   = component.Name;
                        item.Parent = null;

                        cate.Items.Add(item);
                    }

                    toolBox.Categories.Add(cate);
                }
            }

            pnlToolBox.Controls.Add(toolBox);//左边panel添加控件

            #endregion

            #region 添加PropertyPad

            _propertyGrid = new PropertyGrid {
                Dock = DockStyle.Fill
            };
            pnlPropertyGrid.Controls.Add(_propertyGrid);//右边属性表

            #endregion


            #region 添加 "服务" 、 "设计器" 及 "Code"窗口

            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);

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

            serviceContainer.AddService(typeof(System.ComponentModel.Design.IEventBindingService), new ICSharpCode.FormsDesigner.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组件
            rootComponent = (Form)((IDesignerHost)this._host).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);

            #endregion

            _propertyGrid.SelectedObject = surface.ComponentContainer.Components[0];
            SetAlignMenuEnabled(false);


            _propertyGrid.Site = (new IDEContainer(_host)).CreateSite(_propertyGrid);
            _propertyGrid.PropertyTabs.AddTabType(typeof(System.Windows.Forms.Design.EventsTab), PropertyTabScope.Document);

            #region 事件响应

            // 选中项改变时的事件
            _selectionService = surface.GetService(typeof(ISelectionService)) as ISelectionService;//获取surface中的SelectionService
            _selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged);

            // 增/删/重命名组件的事件
            IComponentChangeService componentChangeService = (IComponentChangeService)surface.GetService(typeof(IComponentChangeService));
            componentChangeService.ComponentAdded   += ComponentListChanged;
            componentChangeService.ComponentRemoved += ComponentListChanged;
            componentChangeService.ComponentRename  += ComponentListChanged;
            _host.TransactionClosed += new DesignerTransactionCloseEventHandler(TransactionClosed);

            // 选中不同的工具条项目
            toolBox.SelectedItemChanged += delegate(object sender, Guanjinke.Windows.Forms.ToolBoxItem newItem)
            {
                _toolboxService.SetSelectedToolboxItem(newItem.Tag as System.Drawing.Design.ToolboxItem);
            };

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

            // 拖动工具栏项目的支持代码
            toolBox.ItemDragStart += delegate(object sender, Guanjinke.Windows.Forms.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;
                    toolBox.DoDragDrop(dataObject, DragDropEffects.Copy);
                }
            };

            _toolboxService.ResetToolboxItem += delegate
            {
                toolBox.ResetSelection();
            };


            #endregion

            tsmiDelete.ShortcutKeys    = Keys.Delete;
            tsmiSelectAll.ShortcutKeys = Keys.Control | Keys.A;

            cmbControls.Sorted    = true;
            cmbControls.DrawMode  = DrawMode.OwnerDrawFixed;
            cmbControls.DrawItem += new DrawItemEventHandler(cmbControls_DrawItem);
            UpdateComboBox();

            #region 串口加载

            foreach (string com in System.IO.Ports.SerialPort.GetPortNames())
            {
                this.comPortName.Items.Add(com);
            }
            comParity.SelectedIndex = 0;
            if (comPortName.Items.Count > 0)
            {
                comPortName.SelectedIndex = 0;
            }

            #endregion
        }