using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Systehttp://m.Threading.Tasks;
namespace ex0220_File_입출력.file
{
public class file_control
{
string filepath = "data.txt";
public void write(string text)
{
Console.WriteLine($"write {text}");
File.WriteAllText( filepath, text);
}
public void read()
{
Console.WriteLine("read");
string text = File.ReadAllText(filepath);
Console.WriteLine($"text = {text}");
}
}
}
class 로 따로 뽑아서 적었다.
using ex0220_File_입출력.file;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Systehttp://m.Threading.Tasks;
using Systehttp://m.Windows.Forms;
namespace ex0220_File_입출력
{
public partial class Form1 : Form
{
List<String> list = new List<String>();
file_control fc= new file_control();
public Form1()
{
InitializeComponent();
}
private void 파일쓰기(object sender, EventArgs e)
{
if (textBox1.Text == "") {
MessageBox.Show("글자를 입력하세요");
return;
}
fc.write(textBox1.Text);
list.Add(textBox1.Text);
listBox1.DataSource = null;
listBox1.DataSource = list;
textBox1.Text = "";
//listBox1.Items.Add("추가");
}
private void 불러오기(object sender, EventArgs e)
{
fc.read();
}
}
}
메인 form 이다.
'C#' 카테고리의 다른 글
C# 수업중 내용 최종 (입출력) (0) | 2024.02.21 |
---|---|
c# 수업중 내용2 (0) | 2024.02.20 |
c# 수업중 내용 (0) | 2024.02.19 |
원 처럼 움직이기 (0) | 2024.02.19 |
라벨 이용하기 (0) | 2024.02.16 |