public void AddPage(MouseEventArgs e, TabPage page) { if (e.Button == MouseButtons.Left) { int x = e.X, y = e.Y; Rectangle r = this.GetTabRect(0); int tx = (int)((r.Width * this.TabCount)); r.Offset(tx, 0); r.Width = 30; r.Height = 30; int longw = ((this.TabCount + 1) * this.ItemSize.Width + 30); if (this.Width < longw) { page.Dispose(); return; } bool isAdd = x > r.X && x <r.Right && y> r.Y && y < r.Bottom; if (isAdd) { this.Controls.Add(page); } else { page.Dispose(); } } }
/// <summary> /// 这里是鼠标对tab的点击事件,当发生的时候,获取当前鼠标位置,假如在closebtn上面,那么就直接关闭。 /// </summary> /// <param name="sender"></param> /// <param name="agrs"></param> private void init_click_handler(Object sender, MouseEventArgs agrs) { TabControl t1 = (TabControl)sender; int cSelectedIndex = t1.SelectedIndex; // MessageBox.Show("您点击了我,鼠标位置:" + agrs.X + " " + agrs.Y + " 当前选中的tab为:" +cSelectedIndex); Rectangle rect1 = t1.GetTabRect(t1.SelectedIndex); // MessageBox.Show("当前选中的矩形信息为:left "+rect1.Left+",top "+rect1.Top+",width "+rect1.Width+",height "+rect1.Height+""); Rectangle closeRect = new Rectangle(rect1.X + rect1.Width - 12 - 9, rect1.Y + rect1.Height - 12 - 6, 16, 16); if (closeRect.Contains(new Point(agrs.X, agrs.Y))) { // MessageBox.Show("在close按钮范围里面"); //--假如在close按钮里面,就关闭 // this.TabPages.RemoveAt(cSelectedIndex ); //标签名为NoClosePageName的不关闭 TabPage page = TabPages[cSelectedIndex]; if (page.Name != NoClosePageName) { if (cSelectedIndex > 0) { SelectedIndex = cSelectedIndex - 1; } TabPages.Remove(page); page.Dispose(); } } }
private void LoadDocument(string file, Workspace workspace) { TabPage tab = new TabPage(Path.GetFileNameWithoutExtension(file)); tab.Name = file; // the key // loads and associates the tab page with the document Document doc = workspace.CreateDocument(file, tab); doc.Services.AddService(typeof(IMenuCommandService), new MenuCommandService(doc.Services)); doc.Load(); doc.Services.AddService(typeof(UndoEngine), new UndoRedoEngine(doc.Services)); if (doc.LoadSuccessful) { doc.Modified += OnDocumentModified; workspace.ActiveDocument = doc; ((Control)doc.DesignSurface.View).Dock = DockStyle.Fill; tab.Controls.Add((Control)doc.DesignSurface.View); surfaceTabs.SuspendLayout(); surfaceTabs.TabPages.Add(tab); surfaceTabs.ResumeLayout(); surfaceTabs.SelectedTab = surfaceTabs.TabPages[file]; } else { MessageBox.Show("Unable to load!"); tab.Dispose(); workspace.CloseDocument(doc); } }
public void RemoveProviderPage(string name) { TabPage tabPage = GetTabPage(name); TabPages.Remove(tabPage); tabPage.Dispose(); }
private void CloseTab(TabControl tc, TabPage TabP) { tc.TabPages.Remove(TabP); tabPagesList.Remove(tc.SelectedTab); tabIndex = tabIndex - 1; TabP.Dispose(); }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { TabPage tb = tabControl1.SelectedTab; if (tb == null) { return; } if (tb is IChangeableTab) { var etb = tb as IChangeableTab; if (etb.IsSavingNecessary == true) { DialogResult dr = MessageBox.Show("You are about to close an unsaved document, do you want to save it now?", "MyPad - Save document", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { saveToolStripMenuItem.PerformClick(); } } } tabControl1.SelectedIndex = -1; tabControl1.TabPages.Remove(tb); tb.Dispose(); tabControl1.SelectedIndex = tabControl1.TabCount - 1; SetupActiveTab(); }
public void CloseTab(TabPage tabPage) { CtrlTabPage tab = tabControl.SelectedTab.Tag as CtrlTabPage; tab.Dispose(); tabPage.Dispose(); }
void WebBrowser_Quit(object sender, EventArgs e) { // This event is launched when window.close() is called from script ExtendedWebBrowser brw = sender as ExtendedWebBrowser; if (brw == null) { return; } // See which page it was on... BrowserControl bc = BrowserControlFromBrowser(brw); if (bc == null) { return; } TabPage page = bc.Tag as TabPage; if (page == null) { return; } // We got a page, remove & dispose it. _tabControl.TabPages.Remove(page); page.Dispose(); if (_tabControl.TabPages.Count == 0) { _tabControl.Visible = false; } }
private void btnDelete_Click(object sender, EventArgs e) { int currentIdx = tabControl1.SelectedIndex; TabPage currentTab = tabControl1.SelectedTab; //AlarmControl c = (AlarmControl)currentTab.Controls[0]; tabControl1.TabPages.Remove(currentTab); currentTab.Dispose(); for (int i = currentIdx; i < tabControl1.TabPages.Count - 1; i++) { AlarmControl ac = ((AlarmControl)tabControl1.TabPages[i].Controls[0]); ac.ControlId = i; Properties.Settings.Default["Name" + i] = ac.Name; Properties.Settings.Default["Text" + i] = ac.Description; Properties.Settings.Default["AvgInterval" + i] = ac.AvgInterval; Properties.Settings.Default["IsRunning" + i] = ac.Running; Properties.Settings.Default["Peek" + i] = ac.PeekEnabled; } int idToClear = tabControl1.TabPages.Count - 1; Properties.Settings.Default["Name" + idToClear] = ""; Properties.Settings.Default["Text" + idToClear] = ""; Properties.Settings.Default["AvgInterval" + idToClear] = new TimeSpan(0, 0, 30); Properties.Settings.Default["IsRunning" + idToClear] = false; Properties.Settings.Default["Peek" + idToClear] = true; Properties.Settings.Default.Save(); }
private void mnuCloseTab_Click(object sender, EventArgs e) { TabPage closingPage = tabWindow.SelectedTab; tabWindow.TabPages.Remove(closingPage); closingPage.Dispose(); }
//---------------------------------------------------------- //函式名稱: tsmi_closepage_Click //說明: tabControl [關閉] CLICK事件 //參數: 無 //回傳值: 無 //---------------------------------------------------------- private void tsmi_closepage_Click(object sender, EventArgs e) { TabPage tp = tabControl.TabPages[tabControl.SelectedIndex]; TabPage tp2 = tabControl2.TabPages[tabControl2.SelectedIndex]; if (tp.Text.Substring(0, 2) != "新增") { ShowAlertBox("您不能關閉此系統預設分頁!", "系統警告"); } else { foreach (RichTextBox rtb in tp.Controls) { rtb.Dispose(); //Dispose RichTextBox } foreach (DataGridView dg in tp2.Controls) { dg.Dispose(); //Dispose DataGridView } //Dispose 分頁 tp.Dispose(); tp2.Dispose(); } tp = null; tp2 = null; }
void LoadFiles() { if (Config == null) { return; } tsProgressBar.Visible = true; Enabled = false; GridOpCode.DataSource = null; LastSaveFile = null; // Delete tabs except Instructions for (int x = tabControl1.TabCount - 1; x >= 2; x--) { TabPage t = tabControl1.TabPages[x]; tabControl1.TabPages.Remove(t); t.Dispose(); } if (Result != null) { Result.Instructions.CollectionChanged -= Instructions_CollectionChanged; Result.Instructions.Clear(); Result = null; } new Task(() => { ALoadFiles(); }).Start(); }
public override void CloseTab(int index = -1) { if (SelectedIndex == -1) { return; } if (index == -1) { index = SelectedIndex; } if (TabPages.Count > 0) { (TabPages[index] as DwarfTabPage).Close(); int newSelectedIndex = SelectedIndex; if (index <= SelectedIndex) { newSelectedIndex = SelectedIndex - 1; } TabPage temp = TabPages[index]; TabPages.Remove(TabPages[index]); temp.Dispose(); if (TabPages.Count > 0 && newSelectedIndex == -1) { SelectedIndex = 0; } else { SelectedIndex = newSelectedIndex; } } GC.Collect(); }
protected override void OnMouseClick(MouseEventArgs e) { int index = ActiveIndex; // If we are clicking on an image then raise the ImageClicked event before raising the standard mouse click event // if there if a handler. if (index > -1 && TabImageClick != null && (TabPages[index].ImageIndex > -1 || !string.IsNullOrEmpty(TabPages[index].ImageKey)) && GetTabImageRect(index).Contains(MousePosition)) { OnTabImageClick(new TabControlEventArgs(TabPages[index], index, TabControlAction.Selected)); // Fire the base event base.OnMouseClick(e); } else if (!DesignMode && index > -1 && _StyleProvider.ShowTabCloser && GetTabCloserRect(index).Contains(MousePosition)) { // If we are clicking on a closer then remove the tab instead of raising the standard mouse click event // But raise the tab closing event first TabPage tab = ActiveTab; TabControlCancelEventArgs args = new TabControlCancelEventArgs(tab, index, false, TabControlAction.Deselecting); OnTabClosing(args); if (!args.Cancel) { TabPages.Remove(tab); tab.Dispose(); } } else { // Fire the base event base.OnMouseClick(e); } }
private void tabControl_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { for (int i = 0; i < tabControl.TabCount; i++) { Rectangle r = tabControl.GetTabRect(i); if (r.Contains(e.Location)) { closeTabContextMenuItem.Tag = tabControl.TabPages[i]; reloadStripMenuItem.Tag = tabControl.TabPages[i]; tabContextMenu.LostFocus += (s, ev) => { tabContextMenu.Hide(); }; tabContextMenu.ChangeUICues += (s, ev) => { tabContextMenu.Hide(); }; tabContextMenu.Show(tabControl, e.Location); } } } else if (e.Button == MouseButtons.Middle) { for (int i = 0; i < tabControl.TabCount; i++) { Rectangle r = tabControl.GetTabRect(i); if (r.Contains(e.Location)) { TabPage page = tabControl.TabPages[i]; if (page != null) { page.Dispose(); } } } } }
/// <summary> /// Adds the tab page for the given remapping /// </summary> /// <param name="remapping">The remapping.</param> /// <param name="tabName">Name of the tab.</param> private void AddTabPage(RemappingResult remapping, string tabName) { AttributesOptimizerControl ctl = CreateAttributesOptimizationControl(remapping); if (ctl == null) { return; } m_remappingDictionary[ctl] = remapping; TabPage tempPage = null; try { tempPage = new TabPage(tabName); tempPage.Controls.Add(ctl); TabPage page = tempPage; tempPage = null; tabControl.TabPages.Add(page); } finally { tempPage?.Dispose(); } }
bool CloseCurrentFile() { var ed = CurrentEditor; if (ed == null) { return(true); //done already } TabPage tp = FindTabPage(ed); if (tp == null) { return(true); } if (ed.Modified) { DialogResult dr = MessageBox.Show(tp.Text.Trim('*') + " is modified, save before closing?", "Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Cancel) { return(false); } else if (dr == DialogResult.Yes) { bool cancel = !Save(ed); if (cancel) { return(false); } } } tp.Dispose(); return(true); }
public void RemoveSettingsPage() { TabPage tabPage = GetTabPage(SettingsTabName); TabPages.Remove(tabPage); tabPage.Dispose(); }
private void tsmiReloadTab_Click(object sender, EventArgs e) { string tabFilePath = ""; for (int i = 0; i < uiScriptTabControl.TabCount; i++) { Rectangle tabRect = uiScriptTabControl.GetTabRect(i); if (tabRect.Contains(uiScriptTabControl.PointToClient(_lastClickPosition))) { TabPage tab = uiScriptTabControl.TabPages[i]; tabFilePath = tab.ToolTipText; DialogResult result = CheckForUnsavedScript(tab); if (result == DialogResult.Cancel) { return; } tab.Controls[0].Dispose(); tab.Dispose(); GC.Collect(); } } OpenOpenBotsFile(tabFilePath); }
private bool ClosePage(TabPage page) { try { if (page == null) { return(false); } Form frm = GetTabPageForm(page); if (frm == null) { return(false); } dicTabPages.Remove(string.Format("{0}:{1}", frm.Name, frm.Tag)); frm.Close(); frm.Dispose(); page.Dispose(); frm = null; page = null; return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
/// <summary> /// remove all resources from a tab. to free memory /// NOTE: this is not working... /// </summary> /// <param name="page"></param> public static void Clean(this TabPage page) { var host = (ElementHost)page.Controls[0]; var textBox = (MainTextBox)host.Child; textBox.Dispose(); page.Dispose(); host.Controls.Clear(); }
private void btnRemove_Click(object sender, EventArgs e) { if (tabs.TabCount > 0) { TabPage p = tabs.TabPages[tabs.SelectedIndex]; RemoveTab(tabs.SelectedIndex); p.Dispose(); } }
public static void CerrarTab(Form form) { TabPage tabPage = (TabPage)form.Parent; MetroTabControl tabControl = (MetroTabControl)tabPage.Parent; form.Close(); tabControl.TabPages.Remove(tabPage); tabPage.Dispose(); }
public void Destroy() { clearImg_Click(this, EventArgs.Empty); TabControl control = (TabControl)tabPage.Parent; control.TabPages.Remove(tabPage); this.Dispose(); tabPage.Dispose(); }
/// 手动关闭当前页面 /// <summary> /// 手动关闭当前页面 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainTabControl_MouseDown(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Left) { int x = e.X, y = e.Y; //计算关闭区域 Rectangle myTabRect = this.tabControl1.GetTabRect(this.tabControl1.SelectedIndex); myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + 3), 2); myTabRect.Width = CLOSE_SIZE; myTabRect.Height = CLOSE_SIZE; //如果鼠标在区域内就关闭选项卡 bool isClose = x > myTabRect.X && x <myTabRect.Right && y> myTabRect.Y && y < myTabRect.Bottom; if (isClose == true && !IsCurrentWindowIsCallingTel()) { //仅仅剩下一个tab时返回 if (GetTabControlTabPagesCount() <= 1) { //取消代理 RefreshIESettings(""); GetCurrentBrowser().Navigate(DefaultURL); } else { if (WinformPages.Contains(this.tabControl1.SelectedTab.Name)) { //关闭winform页面 } else { WebBrowser mybor = GetCurrentBrowser(); //释放资源 mybor.Dispose(); mybor.Controls.Clear(); } TabPage page = this.tabControl1.SelectedTab; this.tabControl1.TabPages.Remove(page); bool flag = alowReceiveCallMsg_WebpageIDList.Remove(page.Name); Loger.Log4Net.Info("[MainUI] 手动关闭页面=" + page.Name + ",并且移除alowReceiveCallMsg_WebpageIDList[允许给iframe子页面推送话务消息列表]中的PageID:" + page.Name + ",结果=" + flag); ShowTabPagesLog(); page.Dispose(); GC.Collect(); } } this.GetCurrentBrowser().Document.Window.Focus(); IHTMLWindow2 win = (IHTMLWindow2)this.GetCurrentBrowser().Document.Window.DomWindow; win.focus(); } } catch { } }
public void RemoveTab(int tabIndex) // from right click menu { if (tabIndex >= 0 && tabIndex < TabPages.Count) { TabPage page = TabPages[tabIndex]; UserControls.UserControlCommonBase uccb = page.Controls[0] as UserControls.UserControlCommonBase; uccb.CloseDown(); page.Dispose(); } }
private void closeTabContextMenuItem_Click(object sender, EventArgs e) { ToolStripMenuItem s = (ToolStripMenuItem)sender; TabPage page = s.Tag as TabPage; if (page != null) { page.Dispose(); } }
private static void RemoveQueryTab(Control queryTab) { TabPage tabPage = (TabPage)queryTab.Parent; TabControl tabControl = tabPage.Parent as TabControl; tabControl.TabPages.Remove(tabPage); // Due MDA exception "RaceOnRCWCleanup error when closing a form with WebBrowser control", tab page is destroyed as below tabPage.BeginInvoke((MethodInvoker) delegate { tabPage.Dispose(); }); }
public void disposeTabByID(string tabID) { TabPage page = pages[tabID]; if (page != null) { page.Dispose(); pages[tabID] = null; } }
public void RemoveTab(TabPage page) // from right click menu { UserControls.UserControlCommonBase uccb = page.Controls[0] as UserControls.UserControlCommonBase; if (uccb.AllowClose()) // it must allow a close to remove it { uccb.CloseDown(); page.Dispose(); } }