protected override void OnDragDrop(DragEventArgs drgevent) { if (AllowDrop) { try { if (mblnDragging) { TabPages.Clear(); TabPages.AddRange((TabPage[])mPages.ToArray(typeof(TabPage))); SelectedTab = mDragTab; mblnDragging = false; mDragTab = null; if (AfterDragDrop != null) { AfterDragDrop(this, EventArgs.Empty); } } } catch { } } }
protected override void OnDragOver(System.Windows.Forms.DragEventArgs e) { base.OnDragOver(e); Point pt = new Point(e.X, e.Y); //We need client coordinates. pt = PointToClient(pt); //Get the tab we are hovering over. TabPage hover_tab = GetTabPageByTab(pt); //Make sure we are on a tab. if (hover_tab != null) { //Make sure there is a TabPage being dragged. if (e.Data.GetDataPresent(typeof(TabPage))) { e.Effect = DragDropEffects.Move; TabPage drag_tab = (TabPage)e.Data.GetData(typeof(TabPage)); int item_drag_index = FindIndex(drag_tab); int drop_location_index = FindIndex(hover_tab); //Don't do anything if we are hovering over ourself. if (item_drag_index != drop_location_index) { ArrayList pages = new ArrayList(); //Put all tab pages into an array. for (int i = 0; i < TabPages.Count; i++) { //Except the one we are dragging. if (i != item_drag_index) { pages.Add(TabPages[i]); } } //Now put the one we are dragging it at the proper location. pages.Insert(drop_location_index, drag_tab); //Make them all go away for a nanosec. TabPages.Clear(); //Add them all back in. TabPages.AddRange((TabPage[])pages.ToArray(typeof(TabPage))); //Make sure the drag tab is selected. SelectedTab = drag_tab; } } } else { e.Effect = DragDropEffects.None; } }
protected override void OnDragOver(System.Windows.Forms.DragEventArgs e)//拖過 { base.OnDragOver(e); Point pt = new Point(e.X, e.Y);//抓出目前座標 //We need client coordinates. pt = PointToClient(pt);//將指定的螢幕點的位置計算為工作區座標 (Client Coordinate)。-public class Control內的成員函數 //Get the tab we are hovering over. TabPage hover_tab = GetTabPageByTab(pt);//從工作區座標計算出被重疊的目的TabPage //Make sure we are on a tab. if (hover_tab != null) { //Make sure there is a TabPage being dragged. if (e.Data.GetDataPresent(typeof(TabPage))) { e.Effect = DragDropEffects.Move; TabPage drag_tab = (TabPage)e.Data.GetData(typeof(TabPage)); int item_drag_index = FindIndex(drag_tab); //找出目前TabPage所在位置 int drop_location_index = FindIndex(hover_tab); //找出目前被重疊TabPage所在位置 //Don't do anything if we are hovering over ourself. if (item_drag_index != drop_location_index)//確定有移動 { ArrayList pages = new ArrayList(); //Put all tab pages into an array. for (int i = 0; i < TabPages.Count; i++)//把所有不是被拖拉的物件記錄下來 { //Except the one we are dragging. if (i != item_drag_index) { pages.Add(TabPages[i]); } } //Now put the one we are dragging it at the proper location. pages.Insert(drop_location_index, drag_tab);//把是被拖拉的物件指定到目的之位置 //Make them all go away for a nanosec. TabPages.Clear();//清空所有內容 //Add them all back in. TabPages.AddRange((TabPage[])pages.ToArray(typeof(TabPage)));//重新填入所有頁面 //Make sure the drag tab is selected. SelectedTab = drag_tab;//指定目前顯示頁面 } } } else { e.Effect = DragDropEffects.None; } }
private void SetTabProperties(XtraTabPage page, XtraTabSmartPartInfo smartPartInfo) { page.Text = String.IsNullOrEmpty(smartPartInfo.Title) ? page.Text : smartPartInfo.Title; try { XtraTabPage currentSelection = SelectedTabPage; callComposerActivateOnIndexChange = false; if (smartPartInfo.Position == TabPosition.Beginning) { XtraTabPage[] tabPages = GetTabPages(); TabPages.Clear(); TabPages.Add(page); TabPages.AddRange(tabPages); } else if (TabPages.Contains(page) == false) { TabPages.Add(page); } page.BackColor = smartPartInfo.BackColor; page.ForeColor = smartPartInfo.ForeColor; page.Image = smartPartInfo.Image; page.ImageIndex = smartPartInfo.ImageIndex; page.PageEnabled = smartPartInfo.PageEnabled; page.PageVisible = smartPartInfo.PageVisible; page.ShowCloseButton = smartPartInfo.ShowCloseButton; if (smartPartInfo.Text != null || smartPartInfo.Text != null) // don't apply if not set { page.Text = smartPartInfo.Text ?? smartPartInfo.Title; } page.Tooltip = smartPartInfo.Tooltip; if (smartPartInfo.PageHeaderFont != null) { page.Appearance.Header.Font = smartPartInfo.PageHeaderFont; page.Appearance.Header.Options.UseFont = true; } SelectedTabPage = currentSelection; // preserve selection through the operation } finally { callComposerActivateOnIndexChange = true; } }
public ToolTabs(IEnumerable <ToolTab> tabs, IEnumerable <Bitmap> images) { TabPages.AddRange(tabs.ToArray()); Dock = DockStyle.Fill; this.SizeMode = TabSizeMode.Fixed; this.ItemSize = new System.Drawing.Size(36, 34); this.DrawMode = TabDrawMode.OwnerDrawFixed; this.DrawItem += tabControlDrawItem; this.Images = images.ToArray(); this.Deselected += (sender, args) => { var toolTab = (ToolTab)args.TabPage; toolTab.TabDeselected(); toolTab.ClearEvents(); }; this.Selecting += (sender, args) => { var toolTab = (ToolTab)args.TabPage; toolTab.TabSelected(); }; }