问题描述
实现一个mdi多窗体打开及保存的问题。首先有一个主窗体菜单第一项文件-下设“打开”“保存”2个选项。可以在主窗体中连续打开本地多个TXT文件(副窗体)查看。(其中有子窗体布局功能(层叠,纵向,横向))现在想实现:假设打开C盘下的3个TXT文件,鼠标点击其中的一个TXT文件(激活)然后点击主窗体菜单-“保存”选项把当前处于激活窗台的副窗体中的TXT文件另存为自己想要保存的地方。打开文件的功能已经完成,可是保存的功能不懂怎么编写,请各位高手帮忙提出完整的代码谢谢了~-------------------------------------------------------------------------------------------------------------------------------------主窗体代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespace多功能窗体{publicpartialclassMainForm:Form{publicMainForm(){InitializeComponent();}privatevoidShowTxtBox(stringstrl){Form2f2=newForm2(strl);f2.MdiParent=this;f2.Show();}privatevoid打开ToolStripMenuItem_Click(objectsender,EventArgse){OpenFileDialogopen=newOpenFileDialog();open.Filter="txtfiles(*.txt)|*.txt|Allfiles(*.*)|*.*";DialogResultdr=open.ShowDialog();if(dr==DialogResult.OK){ShowTxtBox(open.FileName);}}privatevoid纵向平铺ToolStripMenuItem_Click(objectsender,EventArgse){LayoutMdi(MdiLayout.TileVertical);}privatevoid横向平铺ToolStripMenuItem_Click(objectsender,EventArgse){LayoutMdi(MdiLayout.TileHorizontal);}privatevoid层叠显示ToolStripMenuItem_Click(objectsender,EventArgse){LayoutMdi(MdiLayout.Cascade);}privatevoid保存ToolStripMenuItem_Click(objectsender,EventArgse){SaveFileDialogsave=newSaveFileDialog();savefile(save.FileName);}}}副窗体代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespace多功能窗体{publicpartialclassForm2:Form{privatestringstrl="";///<summary>//////</summary>///<paramname="strl">文本文件路径</param>publicForm2(stringstrl){InitializeComponent();this.strl=strl;}publicvoidForm2_Load(objectsender,EventArgse){FileStreamfs=null;StreamReadersr=null;try{fs=newFileStream(strl,FileMode.Open);sr=newStreamReader(fs,Encoding.GetEncoding("gb2312"));StringBuildersb=newStringBuilder();stringstrline=sr.ReadLine();while(strline!=null){sb.Append(strline);strline=sr.ReadLine();}this.textBox1.Text=sb.ToString();}catch(IOExceptione1){MessageBox.Show(e1.ToString());}finally{if(sr!=null)sr.Close();if(fs!=null)fs.Close();}}}}