| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 282 人关注过本帖
标题:c#记事本的问题
只看楼主 加入收藏
zx274465257
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-12-24
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
c#记事本的问题
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using namespace 记事本
{
    public partial class Form1 : Form
    {
        private string pathName = null;
        private string SelectText = null;
        private int ChangeText = 0;
        public enum TextChang { NoChang, Chang }
        public Form1()
        {
            InitializeComponent();
        }

        }
        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            StreamReader sr = new StreamReader(openFileDialog1.FileName);
            textmain.Text = sr.ReadToEnd();
            sr.Close();
        }
        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {if(pathName==null)
        {另存为toolStripMenuItem_Click(sender, e);}
        else{textmain.SaveFile(pathName,RichTextBoxStreamType.PlainText);
        }


            //saveFileDialog1.ShowDialog();
            //StreamWriter aw = new StreamWriter(saveFileDialog1.FileName);
            //aw.Write(textmain.Text);
            //aw.Close();只有保存时     
        }
      
        private void 另存为toolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfDlg = new SaveFileDialog();
            sfDlg.Filter = "文本文档(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (sfDlg.ShowDialog() == DialogResult.OK)
            {
                pathName = sfDlg.FileName;
                textmain.SaveFile(sfDlg.FileName, RichTextBoxStreamType.PlainText);
                this.Text = Path.GetFileName(pathName);
            }
        }

}

为什么点击打开以后,不选取文件点取消,程序会故障??
搜索更多相关主题的帖子: 记事本 color 
2012-12-25 10:39
mpi
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:99
专家分:872
注 册:2012-11-14
收藏
得分:20 
下面的程序块,请在条件判断中使用
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
    StreamReader sr = new StreamReader(openFileDialog1.FileName);
            textmain.Text = sr.ReadToEnd();
            sr.Close();

}

厌烦自私贪婪和不劳而获的人。
厌烦代码各种求,而不思进取的人。
本人也是菜鸟,求上进,踏实不浮躁的朋友共同进步。
2012-12-25 11:00
快速回复:c#记事本的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014551 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved