//文件数据导航栏双击事件 private void ucNaviFiles_TreeList_DoubleClick(object sender, EventArgs e) { TreeList tree = sender as TreeList; TreeListHitInfo hi = tree.CalcHitInfo(tree.PointToClient(Control.MousePosition)); if (hi.Node == null) { return; } string nodeName = (string)hi.Node["name"]; Control openFileTool = null; try { //如果已经有这个tabPage XtraTabPage ifTabPage = ComponentOperator.IfHasTabPage(nodeName, this.xtraTabControl_Main); if (ifTabPage != null) { this.xtraTabControl_Main.SelectedTabPage = ifTabPage; return; } //如果是文件夹,则返回 string type = (string)hi.Node["type"]; if (type == "Folder") { return; } //如果文件不存在 string path = (string)hi.Node["path"]; if (!File.Exists(path)) { MessageBox.Show("文件已丢失,请刷新文件目录后再尝试打开。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //如果不包含该TabPage,则新建 string extension = (string)hi.Node["ext"]; string fileType = ComponentOperator.GetFileTypeByExtension(extension); switch (fileType) { case "": if (MessageBox.Show("本系统暂不支持该格式[" + extension + "]的文件,是否尝试使用系统默认程序打开?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { System.Diagnostics.Process.Start(path); } return; case "RichTextEdit": RichEditControl rec = new RichEditControl(); rec.LoadDocument(path); openFileTool = rec; break; case "SpreadSheet": //表格控件 SpreadsheetControl ssc = new SpreadsheetControl(); ssc.LoadDocument(path); openFileTool = ssc; break; case "MapControl": AxMapControl mapControl = new AxMapControl(); mapControl.BeginInit(); //必须有begin和end mapControl.Location = new System.Drawing.Point(0, 0); mapControl.Name = "mapControl"; mapControl.Dock = DockStyle.Fill; //MapControl不支持先声明,后设置,故而直接设置 XtraTabPage xtp = new XtraTabPage(); xtp.Text = nodeName; xtp.Controls.Add(mapControl); mapControl.Dock = DockStyle.Fill; this.xtraTabControl_Main.TabPages.Add(xtp); this.xtraTabControl_Main.SelectedTabPage = xtp; mapControl.EndInit(); //必须有begin和end mapControl.Refresh(); xtp.Refresh(); this.xtraTabControl_Main.Refresh(); this.Refresh(); mapControl.LoadMxFile(path); break; default: return; } } catch (Exception ex) { Console.Write(ex.Message); } finally { if (openFileTool != null) { //TabPage XtraTabPage xtp = new XtraTabPage(); xtp.Text = nodeName; xtp.Controls.Add(openFileTool); openFileTool.Dock = DockStyle.Fill; this.xtraTabControl_Main.TabPages.Add(xtp); this.xtraTabControl_Main.SelectedTabPage = xtp; openFileTool.Refresh(); xtp.Refresh(); this.xtraTabControl_Main.Refresh(); this.Refresh(); } } }