天晴小姐8755
小淘的萌
首先,打开你的开发工具Microsoft visual studio 2005。文件——》新建项目——》项目类型选择visualc#,模板选择windows 应用程序,到此我们已经创建好一个window窗体了!接着修改窗体的属性,窗体名字修改为EditorForm,窗体的text属性修改为你要的命名。在工具箱了选择MenuStrip控件如图,把菜单拖到窗体去!然后选择插入标准项插入完菜单之后,再从工具箱里拖一个RichTextBox到菜单下面,然后选择停靠父容器,最后一个简单的编辑器的界面出来了!如图:-----------------------------------------------------------------------------------------------------------------------------------------好了,界面我们已经设计好了,现在我们来实现功能了!首先从工具箱里面拖一个叫做openFileDialog的控件,这是一个用于打开文件的对话框来的,把这个拖到窗体,然后点击一下OpenFileDialog选定此控件,设置Filter属性默认文本(*xt)|*xt|富文本文件(*f)|*f 。当然以后功能扩充后,可以打开别的文件,例如设置Filter的属性为括号里的(数据库文件(*dat)|*dat|图像文件(*jpg;*bmp;*gif)|*jpg;*bmp;*gif|文本文件(*xt)|*xt|所有文件(**)|**)。(注意,次数是用于打开文件对话框对要打开的文件进行筛选的,我们这里只是做简单的文本编译器,所以支持的格式分别是xt 和f格式的文本),最后双击菜单的打开菜单出现private void 打开OToolStripMenuItem_Click(object sender, EventArgs e){//确定用户选择了文件if (penFileDShowDialog() == DialogROK){//得到用户选择的文件路径和文件名path = penFileDFileName;//读取文件内容LoadFile();}}private void LoadFile(){if (penFileDFilterIndex == 1){//纯文本文件ichTextBLoadFile(path, RichTextBoxStreamTPlainText);}if (penFileDFilterIndex == 2){ichTextBLoadFile(path, RichTextBoxStreamTRichText);}}我们要在里面写代码实现把PC机上的文件打开到我们的编辑器中进行简单的文字编译了,但是在写代码前,我们要定义一个全局变量,用于记录是否文件是新建的,还是打开来编辑的,我们要把这个变量定义为 string path = null ;附上所有代码using System;using SCGeneric;using SComponentModel;using SData;using SDrawing;using SText;using SWForms;namespace SimpleEditor{public partial class EditorForm : Form{string path = null;string isSaved = "n";int initLenglt = 0;public EditorForm(string path){path = path;InitializeComponent();}private void 新建NToolStripMenuItem_Click(object sender, EventArgs e){if (ichTextBTextLength > 0 && (isSEquals("n"))){if (MessageBShow("文件没有保存是否新建文件?", "提示", MessageBoxBYesNo, MessageBoxIWarning) == DialogRYes){ichTextBClear();Text = "简单的编辑器";initLenglt = richTextBTextLength;}}else{ichTextBClear();Text = "简单的编辑器";initLenglt = richTextBTextLength;}}private void 打开OToolStripMenuItem_Click(object sender, EventArgs e){//确定用户选择了文件if (penFileDShowDialog() == DialogROK){//得到用户选择的文件路径和文件名path = penFileDFileName;//读取文件内容OpenFile();}}private void OpenFile(){try{string extName = Substring(LastIndexOf(""));if (extNToLower()Equals("xt")){//纯文本文件ichTextBLoadFile(path, RichTextBoxStreamTPlainText);}if (extNToLower()Equals("f")){ichTextBLoadFile(path, RichTextBoxStreamTRichText);}Text = "文本编辑器" + path;isSaved = "y";}catch (Exception ex){MessageBShow("请选择合适文件,打开失败");}}private void 保存SToolStripMenuItem_Click(object sender, EventArgs e){if(IsNullOrEmpty(path)){saveFileDTitle = "保存为";if (saveFileDShowDialog() == DialogROK){path = saveFileDFileName;SaveFile();}}else{string extNanme=Substring(LastIndexOf(""));if (extNToLower()Equals("xt")){ichTextBSaveFile(path, RichTextBoxStreamTPlainText);}if(extNToLower()Equals("f")){ichTextBSaveFile(path, RichTextBoxStreamTRichText);}}initLenglt = richTextBTextLength;}private void SaveFile(){try{if (saveFileDFilterIndex == 1){//纯文本文件ichTextBSaveFile(path, RichTextBoxStreamTPlainText);}if (saveFileDFilterIndex == 2){ichTextBSaveFile(path, RichTextBoxStreamTRichText);}Text = "文本编辑器" + path;initLenglt = richTextBTextLength;isSaved = "y";}catch (Exception ex){ }}private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e){if (saveFileDShowDialog() == DialogROK){path = saveFileDFileName;SaveFile();}}private void EditorForm_Load(object sender, EventArgs e){剪切TToolStripMenuIEnabled = false;复制CToolStripMenuIEnabled = false;if(!IsNullOrEmpty(path)){OpenFile();}}private void 字体ToolStripMenuItem_Click(object sender, EventArgs e){try{string extName = Substring(LastIndexOf(""));if (extNToLower()Equals("xt")){SettxtFont();}if (extNToLower()Equals("f")){SetRichtextFont();}}catch(Exception ex){}}private void SettxtFont(){if (fontDShowDialog() == DialogROK){Font font = fontDFont;ichTextBFont = font;}}private void SetRichtextFont(){if (fontDShowDialog() == DialogROK){Font font = fontDFont;ichTextBSelectionFont = font;}}private void 字体颜色ToolStripMenuItem_Click(object sender, EventArgs e){string extName = Substring(LastIndexOf(""));if (extNToLower()Equals("f")){if (lorDShowDialog() == DialogROK){Color color = lorDColor;ichTextBSelectionColor = color;}}}private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e){if(richTextBSelectionLength>0){ichTextBCut();}}private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e){ichTextBPaste();}private void 复制CToolStripMenuItem_Click(object sender, EventArgs e){if (richTextBSelectionLength > 0){ichTextBCopy();}}private void richTextBox1_SelectionChanged(object sender, EventArgs e){if (richTextBSelectionLength > 0){剪切TToolStripMenuIEnabled = true;复制CToolStripMenuIEnabled = true;}else{剪切TToolStripMenuIEnabled = false;复制CToolStripMenuIEnabled = false;}}private void 编辑EToolStripMenuItem_Click(object sender, EventArgs e){}private void 全选AToolStripMenuItem_Click(object sender, EventArgs e){ichTextBSelectedTToString();}private void 退出XToolStripMenuItem_Click(object sender, EventArgs e){Close();}private void EditorForm_FormClosing(object sender, FormClosingEventArgs e){if (ichTextBTextLength > initLenglt){ if (MessageBShow("文件没有保存是否退出?", "提示", MessageBoxBYesNo, MessageBoxIWarning) == DialogRNo){Cancel = true;}}}private void 关于AToolStripMenuItem_Click(object sender, EventArgs e){AboutBox aboutbox = new AboutBox();ShowDialog();}private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e){ichTextBUndo();}}}
susanwangyue
一个小的文本编辑器:import ActionListener;import EventListener;import *;import *;import *;import *;import *;import *;public class MiniEdit extends JFrame implements ActionListener { /** * Method main * * * @param args * */ MenuBar menuBar = new MenuBar(); Menu file = new Menu("File"), edit = new Menu("Edit"), help = new Menu("Help"); MenuItem[] menuItem ={ new MenuItem("New"), new MenuItem("Open"), new MenuItem("Save"), new MenuItem("Exit"), new MenuItem("Select All"), new MenuItem("Copy"), new MenuItem("Cut"), new MenuItem("Paste"), new MenuItem("Help") }; TextArea textArea = new TextArea(); String fileName = "NoName"; Toolkit toolKit = TDefaultToolkit(); Clipboard clipboard = toolKSystemClipboard(); //opne and close message dialogs private FileDialog openFileDialog = new FileDialog(this,"Open File",FileDLOAD); private FileDialog saveFileDialog = new FileDialog(this,"Save File",FileDSAVE); public static void main(String[] args) { // TODO: Add your code here MiniEdit MyEdit = new MiniEdit(); MyEshow(); } /** * Method MiniEdit * * */ public MiniEdit() { // TODO: Add your code here setTitle("MiniEdit"); setFont(new Font("Times New Roman",FPLAIN,15)); setBackground(Cblue); setSize(500,500); setMenuBar(menuBar); menuBadd(file); menuBadd(edit); menuBadd(help); for(int i=0;i<4;i++) { add(menuItem[i]); add(menuItem[i+4]); } add(menuItem[8]); add(textArea); addWindowListener(new WindowAdapter(){//关闭窗口的事件监听 public void windowClosing(WindowEvent e){ Window()dispose(); Sxit(0); } }); //add actionListener for(int i=0;i
import *;import *;import *;import *;import *; //Date neededimport PrintWriter;
Cpp:This is a try out codeintmain(){return0;}
这个问题比较大,其实看你写什么样的文本编辑器。做法:简单记事本:用WinForm或者WPF放一个TextBox控件,实现一下多行,放置几个菜单,添加上保存等功能
10分就想要这个源码?要是c#还行,开发比较快,java有点不划算
如果你的文本编辑器保存的文件名叫xt,那么改成html,直接双击打开就可以了。
优质论文问答问答知识库