Exemple #1
0
 private void guiRenderControl_WindowCreated(object sender, UIECreateWindowEventArg e)
 {
     // 刷新当前正在编辑UI控件的树状结构
     RefreshContolsTree();
     // 更改当前选择的窗口
     ClearCurrentSelectWindow();
     AddCurrentSelectWindow(e.NewCreatedWindow);
 }
        protected void NGUIRenderControl_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            try
            {
                Point     pt             = this.PointToClient(new Point(e.X, e.Y));
                Vector2   DropPosition   = new Vector2(pt.X, pt.Y);
                GUISystem guiSystem      = GUISystem.Instance;
                Vector2   screenPosition = guiSystem.ClientToScreen(new Vector2(pt.X, pt.Y));

                if (e.Data.GetDataPresent(typeof(NFileEntity)))
                {
                    NFileEntity entity = (NFileEntity)e.Data.GetData(typeof(NFileEntity));
                    m_owner.CreateStyleWindow(entity, screenPosition);
                }
                else
                {
                    //获得进行"Drag"操作中拖动的字符串
                    string controlType = e.Data.GetData(typeof(string)) as string;

                    // 在拖放的位置创建窗口
                    if (!WindowManager.Instance.IsTypeRegedited(controlType))
                    {
                        return;
                    }

                    Window parentWnd = guiSystem.GetTargetWindow(screenPosition);
                    if (parentWnd == null)
                    {
                        parentWnd = guiSystem.RootWindow;
                    }

                    Window wnd = WindowManager.Instance.CreateWindow(controlType, parentWnd);
                    wnd.AbsolutePosition = screenPosition;
                    if (wnd.AbsoluteSize.Length() == 0)
                    {
                        wnd.Width  = new UIDim(0, 150);
                        wnd.Height = new UIDim(0, 100);
                    }
                    parentWnd.AddChild(wnd);

                    // 发送响应事件
                    if (WindowCreated != null)
                    {
                        UIECreateWindowEventArg createEvent = new UIECreateWindowEventArg(wnd);
                        WindowCreated(this, createEvent);
                    }
                }
            }
            catch (System.Exception ex)
            {
                NexusEditor.Program.ShowException(ex, "Drag drop failed!");
            }
        }