/// <summary> /// 新建文件菜单--菜单>文件>新建 /// </summary> /// <param name="sender">新建文件菜单对象</param> /// <param name="e"></param> private void NewMenuItem_Click(object sender, EventArgs e) { var budle = new TabBundle { IsNew = true, TabTitle = "新增选项卡" + TabAdapter.NextNo.ToString().PadLeft(3, '0'), }; TabAdapter.Add(budle); SetCurrStatus($"新建标题:{budle.TabTitle}"); }
/// <summary> /// 添加TabPage通过TabBundle /// 1. 打开文件 /// 2. 新建文件 /// </summary> /// <param name="bundle">绑定TabPage与FilePath</param> public void Add(TabBundle bundle) { // 创建TabPage var form = CreateForm(EditFormClassName); TabPage page = CreateTabPage(bundle.TabTitle, CreateForm(EditFormClassName)); TabBudles.Add(new TabBundle { TabTitle = bundle.TabTitle, IsNew = bundle.IsNew || !((!string.IsNullOrWhiteSpace(bundle.SrcPath)) && File.Exists(bundle.SrcPath) && Exts.Contains(Path.GetExtension(bundle.SrcPath).ToLower())), TabPage = page }); if ((!string.IsNullOrWhiteSpace(bundle.SrcPath)) && File.Exists(bundle.SrcPath) /* && bundle.SrcFilePath.isPath()*/) { ((RichTextBox)page.Controls.Find("RichTextBox", true).FirstOrDefault()).LoadFile(bundle.SrcPath, RichTextBoxStreamType.PlainText); } bundle.TabPage = page; TabControl.TabPages.Add(page); var index = TabControl.TabPages.IndexOf(page); TabControl.SelectedIndex = index; }
public void OpenFile(string path) { if (!File.Exists(path)) { MainWindow.SetCurrStatus("文件不存在"); return; } var title = Path.GetFileName(path); var bundle = new TabBundle { IsNew = false, IsEdit = false, SrcPath = path, TabTitle = title, TabPage = CreateEditPage(title), }; ((RichTextBox)bundle.TabPage.Controls.Find("RichTextBox", true).FirstOrDefault()).LoadFile(bundle.SrcPath, RichTextBoxStreamType.PlainText); TabControl.TabPages.Add(bundle.TabPage); var index = TabControl.TabPages.IndexOf(bundle.TabPage); TabControl.SelectedIndex = index; TabBudles.Add(bundle); }