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(); } } } }
프로그램 다운로드
반응형
'프로그래밍 > C#' 카테고리의 다른 글
MSDN C#번역31.C# 프로그래밍 가이드 ②Hello World! (0) | 2020.08.19 |
---|---|
MSDN C#번역30.C# 프로그래밍 가이드 ①개요 (0) | 2020.08.19 |
c# StreamReader 유니코드 문자깨짐 해결법 (0) | 2020.08.18 |
c# 윈폼 선 긋기 (0) | 2020.08.18 |
c# 윈폼 버튼 테두리 색상 바꾸기 color (0) | 2020.08.18 |