本文实例为大家分享了c#实现简单文本编辑器的具体代码,供大家参考,具体内容如下
建立一个窗体文件,实现对文件的编辑保存和对txt文件的打开
界面设计:
程序源代码:
//form1.cs using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace txt_editapp { public partial class form1 : form { public form1() { initializecomponent(); } //open file 菜单选项 private void openfiletoolstripmenuitem_click(object sender, eventargs e) { openfiledialog1.filter = "txt files(*.txt)|*.txt"; if(openfiledialog1.showdialog()==dialogresult.ok) { richtextbox1.loadfile(openfiledialog1.filename, richtextboxstreamtype.plaintext); } } //save file 菜单选项 private void savefiletoolstripmenuitem_click(object sender, eventargs e) { savefiledialog1.filter = "txt files(*.txt)|*.txt"; if(savefiledialog1.showdialog()==dialogresult.ok) { richtextbox1.savefile(savefiledialog1.filename, richtextboxstreamtype.plaintext); } } //exit file 菜单选项 private void exittoolstripmenuitem_click(object sender, eventargs e) { close(); } //about 菜单选项 private void abouttoolstripmenuitem_click(object sender, eventargs e) { form2 frm = new form2(); frm.showdialog(); } } } //form2.cs using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace txt_editapp { public partial class form2 : form { public form2() { initializecomponent(); } private void label2_click(object sender, eventargs e) { } } }
运行截图
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论