东秦C#课设002-简单的文本编辑器
来源:互联网 发布:c语言中函数中参数 编辑:程序博客网 时间:2024/05/24 04:57
//加入的拖拽属性失败,dropenter声明方法待查。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;using System.IO;namespace 实验2_文本编辑器{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } //------------------ //----------------- private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "打开文件"; ofd.Filter = "文本文件(*.txt)|*.txt"; ofd.ShowDialog(); String fileName = ofd.FileName; if (File.Exists(fileName)) { FileStream fs = new FileStream(fileName, FileMode.Open); StreamReader sr = new StreamReader(fs, Encoding.Default); richTextBox1.Text = sr.ReadToEnd(); sr.Close(); fs.Close(); } } private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "保存文件"; sfd.Filter = "文本文件(*.txt)|*.txt"; sfd.ShowDialog(); String fileName = sfd.FileName; if (File.Exists(fileName)) { DialogResult result = MessageBox.Show("文件已存在,是否覆盖", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.WriteLine(richTextBox1.Text); sw.Close(); fs.Close(); } } else { FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.WriteLine(richTextBox1.Text); sw.Close(); fs.Close(); } } private void richTextBox1_TextChanged(object sender, EventArgs e) { } //---------------- private void richTextBox1_DragEnter(object sender, EventArgs e) { if (((DragEventArgs)e).Data.GetDataPresent(DataFormats.FileDrop)) { ((DragEventArgs)e).Effect = DragDropEffects.Link; this.richTextBox1.Cursor = System.Windows.Forms.Cursors.Arrow; //指定鼠标形状(更好看) } else { ((DragEventArgs)e).Effect = DragDropEffects.None; } } private void textBox1_DragDrop(object sender, DragEventArgs e) { //GetValue(0) 为第1个文件全路径 //DataFormats 数据的格式,下有多个静态属性都为string型,除FileDrop格式外还有Bitmap,Text,WaveAudio等格式 string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); richTextBox1.Text = path; this.richTextBox1.Cursor = System.Windows.Forms.Cursors.IBeam; //还原鼠标形状 } //---------------- }}
0 0
- 东秦C#课设002-简单的文本编辑器
- 简单的文本编辑器
- 简单的文本编辑器
- C#窗体程序--简单文本编辑器
- 简单的文本编辑器做法
- 一个简单的文本编辑器
- js简单的文本编辑器
- 一个简单的文本编辑器
- 一个简单的文本编辑器
- 手把手教你用C#编写一个简单的文本编辑器
- C# winform下的富文本编辑器
- 简单的文本编辑器 - wxWindows编程事例
- 由Java实现简单的文本编辑器
- 很简单的一个在线文本编辑器
- xheditor文本编辑器的简单实用介绍
- 2.构建一个简单的文本编辑器
- js简单的文本编辑器(所见即所得)
- UNIX文本编辑器VI的简单使用
- 各种回归算法
- sql having 小记
- Chrome无法打开文件的错误 [Not allowed to load local resource: file://XXXX]
- 第一篇博客
- C/C++相互调用
- 东秦C#课设002-简单的文本编辑器
- (八)正交表实验法
- java实现二叉树的三种遍历方式,并把二叉树转为双向链表,输出二叉树
- 0.11之路(三):system模块
- fatal error C1083: Cannot open include file: '..\XX.h': No such file or directory
- I ,P,B帧概念
- 正房跟小三的抗争谁占优势
- FTP判断发送方式
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)