public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (service != null)
                {
                    dlgDrawingBoard dlg = new dlgDrawingBoard();
                    DrawingLayer    lst = value as DrawingLayer;

                    Hotspots     hs   = null;
                    IDrawingPage page = null;
                    hs = context.Instance as Hotspots;
                    if (hs == null)
                    {
                        page = context.Instance as IDrawingPage;
                        if (page != null)
                        {
                            dlg.Attrs = page.PageAttributes;
                        }
                        Control cOwner = context.Instance as Control;
                        if (cOwner != null)
                        {
                            dlg.ImgBK = cOwner.BackgroundImage;
                        }
                        DrawingLayerCollection ls = value as DrawingLayerCollection;
                        dlg.LoadData(ls);
                    }
                    else
                    {
                        lst = (DrawingLayer)hs.Drawings.Clone();
                        dlg.LoadData(hs);
                        hs.clearBK();
                    }

                    try
                    {
                        if (service.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                        {
                            if (hs != null)
                            {
                                value = dlg.lstShapes;
                                hs.InitBK();
                            }
                            else
                            {
                                value = dlg.DrawingLayers;
                                if (page != null)
                                {
                                    page.PageAttributes = dlg.Attrs;
                                }
                            }
                        }
                        else
                        {
                            if (hs != null)
                            {
                                hs.SetDrawings(lst);
                                hs.InitBK();
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        DrawingItem.ShowMessage(err.Message);
                    }
                }
            }
            return(value);
        }
Пример #2
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            sHelp = "";
            if (curDrawing != null)
            {
                float x1, y1;
                bool  bAdded;
                systemToCustomerXY(e.X, e.Y, out x1, out y1);
                System.Windows.Forms.MouseEventArgs e1  = new System.Windows.Forms.MouseEventArgs(e.Button, e.Clicks, (int)x1, (int)y1, e.Delta);
                System.Windows.Forms.DialogResult   ret = curDrawing.CallDlgDrawingsMouseDown(this, e1, ref nStep, this);
                switch (ret)
                {
                case System.Windows.Forms.DialogResult.OK:
                    if (nType == 0)
                    {
                        bAdded = this.DrawingLayers[0].AddDrawing(curDrawing);
                    }
                    else
                    {
                        bAdded = lstShapes.AddDrawing(curDrawing);
                        hs.SetDrawings(lstShapes);
                        formHS.Show();
                        formHS.TopMost = true;
                        formHS.Invalidate();
                    }
                    if (bAdded)
                    {
                        AddDrawing(curDrawing);
                    }
                    else
                    {
                    }
                    editor.SelectItem(curDrawing);
                    curDrawing.FinishDesign();
                    curDrawing = null;
                    nStep      = 0;
                    editor.Show();
                    break;

                case System.Windows.Forms.DialogResult.Cancel:
                    curDrawing.FinishDesign();
                    curDrawing = null;
                    nStep      = 0;
                    editor.Show();
                    break;

                case System.Windows.Forms.DialogResult.Retry:
                    nStep = 0;
                    break;

                case System.Windows.Forms.DialogResult.None:
                    break;
                }
                this.Invalidate();
            }
            else
            {
                Point       p    = new Point(e.X, e.Y);
                DrawingItem item = HitTest(p);
                if (item != null)
                {
                    SetItemSelection(item);
                    if (e.Button == MouseButtons.Right)
                    {
                        MenuItem[] menus = item.GetContextMenuItems(p);
                        if (menus != null && menus.Length > 0)
                        {
                            ContextMenu cm = new ContextMenu();
                            cm.MenuItems.AddRange(menus);
                            cm.Show(this, p);
                        }
                    }
                }
                else
                {
                    ClearMarks();
                    if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
                    {
                        Type t = _toolBox.SelectedToolboxItem;
                        if (t != null)
                        {
                            DrawingItem newObj = (DrawingItem)Activator.CreateInstance(t);
                            if (_defaultDrawings == null)
                            {
                                _defaultDrawings = new DefaultDrawings();
                            }
                            DrawingItem def = _defaultDrawings.GetDefaultDrawing(newObj.GetType());
                            if (def != null)
                            {
                                newObj.Copy(def);
                            }
                            _toolBox.ClearToolboxSelection();
                            newObj.ResetGuid();
                            makeNewName(newObj);
                            newObj.Page     = this;
                            newObj.Location = p;
                            AddDrawing(newObj);
                            editor.SelectItem(newObj);
                            editor.RefreshPropertyGrids();
                            _newObj = newObj;
                            SetItemSelection(newObj);
                        }
                    }
                }
            }
        }