110,569
社区成员
发帖
与我相关
我的任务
分享
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string filename = "";
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofn = new OpenFileDialog();
byte[] data = { };
if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
data = System.IO.File.ReadAllBytes(ofn.FileName);
textBox1.Text = Encoding.Unicode.GetString(data.Select(x => (byte)(x ^ 0x3b)).ToArray());
filename = ofn.FileName;
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (filename == "")
{
saveAsToolStripMenuItem_Click(sender, e);
}
else
{
byte[] data = Encoding.Unicode.GetBytes(textBox1.Text).Select(x => (byte)(x ^ 0x3b)).ToArray();
System.IO.File.WriteAllBytes(filename, data);
}
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
filename = sfd.FileName;
saveToolStripMenuItem_Click(sender, e);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("really exit?", "editor", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
{
e.Cancel = true;
}
}
}
}