public GroupPanel(int l = 0) { InitializeComponent(); Id = Guid.NewGuid().ToString(); AllowDrop = true; dragTo = DragTo.None; DoubleBuffered = true; SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); UpdateStyles(); tpanel = new TabControl() { Dock = DockStyle.Fill }; tpanel.MouseDown += tpanel_MouseDown; tpanel.MouseUp += tpanel_MouseUp; tpanel.Enter += Tpanel_Enter; Controls.Add(tpanel); level = l; }
protected override void OnDragLeave(EventArgs e) { tp_mask.Visible = false; dragTo = DragTo.None; }
protected override void OnDragDrop(DragEventArgs drgevent) { tp_mask.Visible = false; if (dragTo == DragTo.None) { return; } var data = drgevent.Data.GetData(typeof(DragData)) as DragData; if (data == null) { return; } if (tpanel.TabPages.Count == 1 && data.Id == Id) { return; } if (dragTo == DragTo.Center) { if (data.Id == Id) { return; } tpanel.TabPages.Add(data.Tab); tpanel.Visible = true; if (spanel != null) { spanel.Visible = false; } } else { if (tpanel.TabPages.Count == 1 && data.Id == Id) { return; } var tps1 = new List <TabPage>(); var tps2 = new List <TabPage>(); tps1.Add(data.Tab); tpanel.TabPages.Remove(data.Tab); tps2.AddRange(tpanel.TabPages.Cast <TabPage>().ToArray()); InitSpanel(); if (dragTo == DragTo.Top || dragTo == DragTo.Left) { spanel.SetTabs(tps1.ToArray(), tps2.ToArray()); } else { spanel.SetTabs(tps2.ToArray(), tps1.ToArray()); } if (dragTo == DragTo.Top || dragTo == DragTo.Bottom) { spanel.SetDirection(Orientation.Horizontal); } else { spanel.SetDirection(Orientation.Vertical); } dragTo = DragTo.None; tpanel.Visible = false; spanel.Visible = true; } data.Source.DropDone(); }
protected override void OnDragOver(DragEventArgs drgevent) { var data = drgevent.Data.GetData(typeof(DragData)) as DragData; if (data == null) { return; } drgevent.Effect = DragDropEffects.Move; var wsd = Width / 3; var hsd = Height / 3; var pt = PointToClient(new Point(drgevent.X, drgevent.Y)); if (pt.X > wsd && pt.X < Width - wsd && pt.Y > hsd && pt.Y < Height - hsd) { if (data.Id == Id) { return; } tp_mask.Width = Width; tp_mask.Height = Height; tp_mask.Left = 0; tp_mask.Top = 0; tp_mask.Visible = true; dragTo = DragTo.Center; } else if (pt.X < wsd || pt.Y < hsd) { if (pt.X < wsd || pt.X < pt.Y) { tp_mask.Width = Width / 2; tp_mask.Height = Height; dragTo = DragTo.Left; } else { tp_mask.Width = Width; tp_mask.Height = Height / 2; dragTo = DragTo.Top; } tp_mask.Left = 0; tp_mask.Top = 0; tp_mask.Visible = true; } else if (pt.X > Width - wsd || pt.Y > Height - hsd) { if (pt.X > Width - wsd || pt.X > pt.Y) { tp_mask.Width = Width / 2; tp_mask.Height = Height; tp_mask.Left = Width - tp_mask.Width; tp_mask.Top = 0; dragTo = DragTo.Right; } else { tp_mask.Width = Width; tp_mask.Height = Height / 2; tp_mask.Top = Height - tp_mask.Height; tp_mask.Left = 0; dragTo = DragTo.Bottom; } tp_mask.Visible = true; } else { tp_mask.Visible = false; dragTo = DragTo.None; } }