// 判断是否要关闭标签 private void doIsDelPage(MouseButtons mouse) { if (mouse.Equals(MouseButtons.Left)) { int delIndex = GetMouseDelPageIndex(); // 点击关闭按钮时移除标签 if (IsShowDelPageBut && delIndex >= 0) { if (isDelPageAskMethod()) { MainTabControlUtils.DeleteTabPage(this, this.TabPages[delIndex]); } } } else if (mouse.Equals(MouseButtons.Middle)) // 按下鼠标滚轮 { int delIndex = getMouseLocPage(this, MousePagePoint); if (IsClickMiddleDelPage && delIndex >= 0) { if (isDelPageAskMethod()) { MainTabControlUtils.DeleteTabPage(this, this.TabPages[delIndex]); } } } }
/// <summary> /// 实例化文件保存对话框保存文本 /// </summary> /// <param name="t">要保存内容的文本框</param> /// <returns></returns> public static object saveFileMethod(TextBox t) { SaveFileDialog newSaveFile = new SaveFileDialog(); Dictionary <string, object> textTag = TextBoxUtils.GetTextTagToMap(t); newSaveFile.RestoreDirectory = false; newSaveFile.ValidateNames = true; newSaveFile.DefaultExt = "txt"; if (t != null && t.Parent != null) { newSaveFile.FileName = t.Parent.Text; } newSaveFile.Filter = "文本文档(*.txt)|*.txt|所有文件(*.*)|*.*"; // 获取文本框保存的Ecoding Encoding encoding = Encoding.Default; if (textTag.ContainsKey(TextBoxTagKey.TEXTBOX_TAG_KEY_ECODING) && textTag[TextBoxTagKey.TEXTBOX_TAG_KEY_ECODING] is Encoding) { encoding = (Encoding)textTag[TextBoxTagKey.TEXTBOX_TAG_KEY_ECODING]; } //判断是否点击确定 if (newSaveFile.ShowDialog() == DialogResult.OK) { string path = newSaveFile.FileName; // 调用方法写入文件内容 FileUtils.FileWrite.WriteFile(path, t.Text, encoding); // 将保存路径加入到文本框的Tag属性 TextBoxUtils.TextBoxAddTag(t, TextBoxTagKey.SAVE_FILE_PATH, newSaveFile.FileName); // 监听文件变化并弹窗提醒 传入的文本框为null则开启一个新标签 TextBox tempTextB = t != null? t : MainTabControlUtils.GetNewPageTextBox(); FileUtils.SetTextBoxValByPath(tempTextB, path, encoding); } return(newSaveFile); }
/// <summary> /// 显示添加标签按钮 /// </summary> /// <param name="isShow">是否显示</param> /// <param name="transfer">是否立即调用一次点击事件</param> public void ShowAddPageButtton(bool isShow, bool transfer) { ShowAddPageButtton(isShow, transfer, new AddPageButInvoker(delegate { TabPage page = new RedrawTabPage(); this.TabPages.Add(page); MainTabControlUtils.AddMainTextToPage(page, new RedrawTextBox()); this.SelectedTab = page; })); }
// 窗口加载时判断是否有拖动到上面的文件 private void loadOpenFile() { if (loadPath != null && loadPath.Length > 0) { foreach (string p in loadPath)// 遍历路径 { FileUtils.SetTextBoxValByPath(MainTabControlUtils.GetNewPageTextBox(), p, Encoding.UTF8); } } }
// 下拉框选择子项事件 private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { ComboBox comB = (ComboBox)sender; if (outputComBox != null && outputComBox.Equals(comB) && comB.Focused) { List <Dictionary <string, string> > dataDic = dateTabelStrToList(inputDGV); // 获取最终内容 string str = beGetSetTotalMethod(dataDic); ExportComBoxValEnum val = ExportComBox.stringToEnum(comB.SelectedValue.ToString()); switch (val) { case ExportComBoxValEnum.EXPORT_NEW_PAGE_VAL: // 新标签 if (str.Length > 0) { MainTabControlUtils.ExportNewPage(str); } break; case ExportComBoxValEnum.EXPORT_THIS_PAGE_VAL: // 当前标签 if (str.Length > 0) { ControlsUtils.ExportThisPage(str); } break; case ExportComBoxValEnum.EXPORT_JAVA_VAL: // java文件 if (str.Length > 0) { FileUtils.SaveJavaFile(str, classNameStr, encoding); } break; case ExportComBoxValEnum.EXPORT_NOTEBOOK_VAL: // 记事本 if (str.Length > 0) { FileUtils.TurnOnNotepad(str); } break; } } if (输入_类型规则_comB.Equals(comB) && comB.Focused) { if ("数据库".Equals(comB.SelectedItem)) { TypeRule = 0; } else if ("JAVA对象".Equals(comB.SelectedItem) && comB.Focused) { TypeRule = 1; } } }
/// <summary> /// 判断标签是否要转化为独立的窗口 /// </summary> private void doIsPageToForm() { // 已设置可以转化为独立的窗口 并且 一直按下了鼠标左键 TabPage selPage = this.SelectedTab; if (IsPageToAbsoluteForm && !isPageSuccessToForm && MouseButtons.Left.Equals(MouseClickButtons) && selPage != null) { Rectangle rectangle = this.GetTabRect(this.SelectedIndex); int y = MousePagePoint.Y; if (y < -10 || y > rectangle.Height + 10) { MainTabControlUtils.PageToForm(this, this.SelectedIndex, true); isPageSuccessToForm = true; } } }
/// <summary> /// 实例化文本选择对话框 /// </summary> /// <param name="t">为null则打开一个新标签</param> /// <returns>该对话框</returns> public static object openFileMethod(TextBox t) { OpenFileDialog openFile = new OpenFileDialog(); openFile.CheckFileExists = true; openFile.DefaultExt = "txt"; openFile.Filter = "文本文档(*.txt)|*.txt|所有文件(*.*)|*.*"; openFile.DereferenceLinks = true; openFile.Multiselect = true; openFile.RestoreDirectory = false; // 判断是否点击确定 if (openFile.ShowDialog() == DialogResult.OK) { string path = openFile.FileName; // 判断编码 Encoding encoding = FileUtils.GetType(path); TextBox tempTextB = t != null? t : MainTabControlUtils.GetNewPageTextBox(); FileUtils.SetTextBoxValByPath(tempTextB, path, encoding); } return(openFile); }
// 判断删除标签后的显示模式 private void delPageIsPageMode(TabPage page) { int selIndex = this.SelectedIndex; // 获取要删除的标签的索引 int delIndex = MainTabControlUtils.GetTabIndex(this, page); this.TabPages.Remove(page); // 确定移除标签后的要显示的标签 if (selIndex >= 0) { cancelSelectPage = false; if (selIndex.Equals(delIndex)) { MainTabControlUtils.DoIsdelPageSelMode(this, delIndex); } else { this.SelectedIndex = selIndex; } } }
/// <summary> /// 导出数据到新标签 /// </summary> public void exportNewPage() { string s = resultTextBox.SelectionLength == 0? resultTextBox.Text : resultTextBox.SelectedText; MainTabControlUtils.ExportNewPage(s); }