C# 메모장 프로그램 간소화, 정말 편해다!

Posted by 슈퍼너드 리보
2020. 8. 18. 23:49 프로그래밍/C#
반응형

모바일 프로그램들은 너무나도 간편해지고 있는데 윈도우10 프로그램들은 아직도 구닥다리인거 같더군요. 그래서 한번 만들어봤습니다. 메모장 프로그램입니다.

소스코드

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 memo1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

    
        private void Open_Click(object sender, EventArgs e)
        {
            //파일오픈창 생성 및 설정
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "파일 오픈창";
            ofd.FileName = "";
            ofd.Filter = "텍스트 파일 (*.txt) | *.txt";

            //파일 오픈창 로드
            DialogResult dr = ofd.ShowDialog();

            //OK버튼 클릭시
            if (dr == DialogResult.OK)
            {

                //프로퍼티
                //File명만 뽑는다
                string fileNamel = ofd.SafeFileName.Substring(0, ofd.SafeFileName.Length - 4);
                StreamReader sr = new StreamReader(ofd.FileName, Encoding.UTF8);

                int position = ofd.FileName.LastIndexOf("\\");

                string textFileName = ofd.FileName.Substring(position + 1);

                this.Text = textFileName + " - Libo메모장";

                //출력 로직

                contents.Text = sr.ReadToEnd();
                sr.Close();


            }
        }

 

        private void Reset_Click(object sender, EventArgs e)
        {
            contents.Text = string.Empty;
        }



        

        private void Save_Click(object sender, EventArgs e)
        {

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "텍스트 파일 (*.txt) | *.txt";

            if (sfd.ShowDialog() == DialogResult.OK)

            {


                FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);

                StreamWriter sw = new StreamWriter(fs);

                sw.WriteLine(contents.Text); // 파일 저장
                sw.Close();

                                                              


            }


        }


    }
}

프로그램 다운로드

memo1.exe


반응형