using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace mook_FileMove
{
public partial class Form1 : Form
{
private string filePath = null; //파일 경로
private string imgPath = null; //이미지 경로
private Image img = null; //이미지 설정
DirectoryInfo di; //폴더 정보를 알기 위해
FileInfo f; //파일 정보를 알기 위해
public Form1()
{
InitializeComponent();
}
private void btnFileOpen_Click(object sender, EventArgs e)
{
this.ofdFile.Filter = "텍스트 문서(*.txt)|*.txt";
if (this.ofdFile.ShowDialog() == DialogResult.OK)
filePath = this.ofdFile.FileName;
}
private void btnImgOpen_Click(object sender, EventArgs e)
{
this.ofdFile.Filter = "이미지(*.bmp)|*.bmp|(*.gif)|*.gif|(*.jpg)|*.jpg";
if (this.ofdFile.ShowDialog() == DialogResult.OK)
{
imgPath = this.ofdFile.FileName;
img = Image.FromFile(this.imgPath);
}
}
private void btnFileMove_Click(object sender, EventArgs e)
{
try
{
if (this.filePath == null)
MessageBox.Show("파일을 선택해 주세요.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
this.sfdFile.Filter = "텍스트 문서(*.txt)|*.txt";
var sr = new StreamReader(this.filePath, Encoding.Default);
if (this.sfdFile.ShowDialog() == DialogResult.OK)
{
StreamWriter sw;
sw = File.CreateText(this.sfdFile.FileName);
sw.WriteLine(sr.ReadToEnd());
sw.Close();
sr.Close();
filePath = null;
f = new FileInfo(this.sfdFile.FileName);
di = f.Directory;
FileView(di.FullName);
}
}
}
catch
{
MessageBox.Show("파일을 저장하는데 오류가 발생했네요..", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FileView(string pd)
{
int FileNum = 0;
this.lvView.Items.Clear();
try
{
if (Directory.Exists(pd) == false)
{
MessageBox.Show(pd + " 폴더는 읽을 수 없습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
var dr = new DirectoryInfo(pd);
foreach (var d in dr.GetFiles())
{
string str = d.Extension;
str = str.ToLower();
switch (str.ToString())
{
case ".bmp":
FileNum = 0;
break;
case ".gif":
FileNum = 1;
break;
case ".jpg":
FileNum = 2;
break;
case ".txt":
FileNum = 3;
break;
}
var lvi = new ListViewItem(new String[] { d.Name, d.Extension, d.Length.ToString() }, FileNum);
this.lvView.Items.Add(lvi);
}
}
}
catch
{
MessageBox.Show("오류가 발생하였습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnImgMove_Click(object sender, EventArgs e)
{
try
{
if (this.imgPath == null)
MessageBox.Show("이미지를 선택해 주세요.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
this.sfdFile.Filter = "이미지(*.bmp)|*.bmp|(*.gif)|*.gif|(*.jpg)|*.jpg";
if (this.sfdFile.ShowDialog() == DialogResult.OK)
{
var NewImage = new Bitmap(img);
this.pbView.Image = NewImage;
NewImage.Save(this.sfdFile.FileName);
f = new FileInfo(this.sfdFile.FileName);
di = f.Directory;
FileView(di.FullName);
MessageBox.Show("정상적으로 데이터가 저장되었습니다.", "알림메시지", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch
{
MessageBox.Show("파일을 저장하는데 오류가 발생했네요..", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cbbView_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.cbbView.SelectedItem.ToString() == "큰 아이콘")
{
this.lvView.View = View.LargeIcon;
}
else if (this.cbbView.SelectedItem.ToString() == "작은 아이콘")
{
this.lvView.View = View.SmallIcon;
}
else
this.lvView.View = View.Details;
}
}
}
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
24 |
웹브라우저 (심화판)
![]() | 관리자2 | 2019.01.02 | 910 |
» |
파일,이미지 열기,옮기기
![]() | 관리자2 | 2019.01.02 | 449 |
22 |
다운로드 폼 구현
![]() | 관리자2 | 2019.01.02 | 246 |
21 |
프로세스 관리자
![]() | 관리자2 | 2019.01.02 | 155 |
20 |
노드 확장 구현
![]() | 관리자2 | 2019.01.02 | 151 |
19 |
전화번호부 구현
![]() | 관리자 | 2018.12.30 | 187 |
18 |
탭메뉴로 컴퓨터 속성 구현
![]() | 관리자 | 2018.12.30 | 145 |
17 |
폰트바꾸기
![]() | 관리자 | 2018.12.30 | 262 |
16 |
웹브라우저 예제
![]() | 관리자 | 2018.12.30 | 194 |
15 |
트레이 아이콘 사용하기
![]() | 관리자 | 2018.12.30 | 147 |
14 |
메뉴관리 폼
![]() | 관리자 | 2018.12.30 | 175 |
13 |
선택 입출력 박스 사용하기
![]() | 관리자 | 2018.12.29 | 155 |
12 |
파일찾기 사용하기
![]() | 관리자2 | 2018.12.26 | 154 |
11 |
설문조사구현
![]() | 관리자2 | 2018.12.26 | 220 |
10 |
일기장 구현하기
![]() | 관리자2 | 2018.12.26 | 270 |
9 |
프로세싱박스 만들기
![]() | 관리자2 | 2018.12.26 | 152 |
8 |
사진 투명도 조절하기
![]() | 관리자2 | 2018.12.26 | 155 |
7 |
콤보박스로 구구단 구현하기
![]() | 관리자2 | 2018.12.24 | 169 |
6 |
리스트사용하기
![]() | 관리자2 | 2018.12.24 | 150 |
5 |
로그인창
![]() | 관리자2 | 2018.12.24 | 894 |
4 |
웹사이트 이동하기
![]() | 관리자2 | 2018.12.24 | 191 |
3 |
메시지박스 사용하기
![]() | 관리자2 | 2018.12.24 | 154 |
2 |
TextBox사용하기
![]() | 관리자2 | 2018.12.24 | 151 |
1 |
Hello, World
![]() | 관리자2 | 2018.12.24 | 154 |