|
 |
|
ช่วยด้วยคร๊าฟ มีปัญหาในการ แก้ไข และ ลบ ไฟล์ .Text ใน C# |
|
 |
|
|
 |
 |
|
ทดสอบเขียนโปรแกรมดังภาพ

จากนั้นให้อ่าน Code ต่อไปนี้
Code (C#)
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 TestEditText
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
// ปุ่ม Open
private void btOpen_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Title = "Select Text File";
openFileDialog.Multiselect = false;
openFileDialog.Filter = "Text File (*txt)|*.txt";
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtPath.Text = openFileDialog.FileName;
this.btSave.Enabled = true;
OpenTextFile(openFileDialog.FileName);
}
}
}
// ปุ่ม Save
private void btSave_Click(object sender, EventArgs e)
{
SaveTextFile(this.txtPath.Text);
MessageBox.Show("Save OK", this.Text, MessageBoxButtons.OK);
}
// ปุ่ม Close
private void btClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void OpenTextFile(string path)
{
using (StreamReader sr = new StreamReader(path, Encoding.Default))
{
this.txtEdit.Text = sr.ReadToEnd();
sr.Close();
}
}
private void SaveTextFile(string path)
{
using (StreamWriter sw = new StreamWriter(path, false, Encoding.Default))
{
sw.Write(this.txtEdit.Text);
sw.Close();
}
}
}
}
รายละเอียดต่าง ๆ จขกท. น่าจะพอเข้าใจชื่อตัวแปร และชื่อคอนโทรล คงไม่ยากเกินไปนะครับที่จะทำให้มันรันได้ โชคดีครับ
|
 |
 |
 |
 |
Date :
2014-05-06 00:43:46 |
By :
gunnermontana |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|