private void save_tab(TabPage P, string path) { System.IO.StreamWriter file = new System.IO.StreamWriter(path); file.Write(P.Controls[0].Controls["editor"].Text); textEditor UC = (textEditor)P.Controls[0]; UC.isModified = false; tabControl1.Invalidate(); file.Close(); }
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { Graphics g = e.Graphics; Brush _TextBrush; // Get the item from the collection. TabPage _TabPage = tabControl1.TabPages[e.Index]; // Get the real bounds for the tab rectangle. Rectangle _TabBounds = tabControl1.GetTabRect(e.Index); if (_TabPage.Controls[0] is textEditor) { textEditor F = (textEditor)_TabPage.Controls[0]; if (F.isModified) { _TextBrush = new SolidBrush(Color.Red); } else { _TextBrush = new System.Drawing.SolidBrush(e.ForeColor); } } else { _TextBrush = new System.Drawing.SolidBrush(e.ForeColor); } if (e.State == DrawItemState.Selected) { // Draw a different background color, and don't paint a focus rectangle. g.FillRectangle(Brushes.LightGray, e.Bounds); } // Use our own font. Because we CAN. Font _TabFont = new Font(e.Font.FontFamily, (float)9, FontStyle.Regular, GraphicsUnit.Pixel); //Font fnt = new Font(e.Font.FontFamily, (float)7.5, FontStyle.Bold); // Draw string. Center the text. StringFormat _StringFlags = new StringFormat(); _StringFlags.Alignment = StringAlignment.Center; _StringFlags.LineAlignment = StringAlignment.Center; g.DrawString(tabControl1.TabPages[e.Index].Text, _TabFont, _TextBrush, _TabBounds, new StringFormat(_StringFlags)); }
private void save_tab(TabPage P) { fileInfo F = (fileInfo)P.Tag; if (F == null || info.sound_Filetypes.Contains(F.Extension)) { return; } System.IO.StreamWriter file = new System.IO.StreamWriter(F.FullPath); file.Write(P.Controls[0].Controls["editor"].Text); F.Text = P.Controls[0].Controls["editor"].Text; textEditor UC = (textEditor)P.Controls[0]; UC.isModified = false; tabControl1.Invalidate(); file.Close(); } // ;
private void mainWindow_FormClosing(object sender, FormClosingEventArgs e) { foreach (TabPage _tabPage in tabControl1.TabPages) { textEditor F = (textEditor)_tabPage.Controls[0]; if (F.isModified) { if (ask_save_all()) { return; } else { e.Cancel = true; } return; } } }
private void tabControl1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { for (int x = 0; x < tabControl1.TabCount; x++) { Rectangle R = tabControl1.GetTabRect(x); if (R.Contains(e.Location)) { tab_menu.Tag = tabControl1.TabPages[x]; Point F = tabControl1.PointToScreen(e.Location); tab_menu.Show(F); } } } else if (e.Button == System.Windows.Forms.MouseButtons.Middle) { for (int x = 0; x < tabControl1.TabCount; x++) { Rectangle R = tabControl1.GetTabRect(x); if (R.Contains(e.Location)) { TabPage _tabPage = tabControl1.TabPages[x]; textEditor F = (textEditor)_tabPage.Controls[0]; if (!F.isModified) { close_tab(_tabPage); } else { if (!ask_save_tab(_tabPage)) { return; } close_tab(_tabPage); } } } } }