东秦C#课设002-简单的文本编辑器

//加入的拖拽属性失败,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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目录 封面 ...........................1 目录 ...........................2 1.设计任务书.......................4  1.1题目与要求 .....................4  1.2本系统涉及的知识点 .................4 2.功能设计........................4 3.数据库设计.......................5 3.1数据库概念设计(E-R图) ...............5 3.2数据库逻辑结构设计 .................6 3.3数据库物理设计 ...................6 系统实现........................6 4.1界面设计及实现 ...................6 4.2部门信息管理设计及实现...............11 4.2.1添加部门信息...................11 4.2.2浏览部门信息...................13 4.2.3修改部门信息...................14 4.2.4删除部门信息...................16 5.总结..........................18 致谢 ...........................18 参考文献 .........................18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值