C # Notepad

Source: Internet
Author: User
Tags save file


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 notepads
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<string> a = new List<string>();
Private void open toolstripmenuitem [click (object sender, EventArgs E)
{
Openfiledialog open = new openfiledialog(); / / create dialog
Open. Initialdirectory = @ "C: \ documents and settings \ all users \ desktop"; / / set dialog path
Open. Title = "dialog 1"; / / dialog title
Open. Filter = "text document" | *. TXT "| all files" * ";
Open. Multiselect = true; / / multiselect
Open. Showdialog(); / / open the dialog
//string[] paths = open.FileName;
String paths = open. Filename; / / read the full path of the file
if (paths == "") return;
using (FileStream file = new FileStream(paths, FileMode.OpenOrCreate, FileAccess.Read))
{
byte[] bytes = new byte[1024 * 1024 * 5];
int r = file.Read(bytes, 0, bytes.Length);
this.textBox1.Text = Encoding.Default.GetString(bytes, 0, r);
}
string ax = Path.GetFileName(paths);
listBox1.Items.Add(ax);
a.Add(paths);
}
Private void save toolstripmenuitem [click (object sender, EventArgs E)
{
Savefiledialog SD = new savefiledialog(); / / create
//Save file dialog box
SD. Initialdirectory = @ "C: \ documents and settings \ all users \ desktop"; / / set dialog path
SD. Title = "dialog 1"; / / dialog title
Sd.filter = "text document" | *. TXT "| all files" * ";
sd.ShowDialog();
string path = sd.FileName;
if (path == "") return;
using (FileStream fsv = new FileStream(path, FileMode.Create, FileAccess.Write))
{
byte[] bytes = Encoding.Default.GetBytes(this.textBox1.Text);
fsv.Write(bytes, 0, bytes.Length);
}
}
Private void auto wrap toolstripmenuitem [click (object sender, EventArgs E)
{
if (this.textBox1.WordWrap == true)
{
this.textBox1.WordWrap = false;
}
Else {
this.textBox1.WordWrap = true;
}
}
Private void font toolstripmenuitem [click (object sender, EventArgs E)
{
FontDialog fonts = new FontDialog();
fonts.ShowDialog();
this.textBox1.Font = fonts.Font;
}
Private void color toolstripmenuitem [click (object sender, EventArgs E)
{
ColorDialog color = new ColorDialog();
color.ShowDialog();
this.textBox1.ForeColor = color.Color;
}
Private void displays toolstripmenuitem [click (object sender, EventArgs E)
{
panel1.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
//String [] path = directory.getfiles (@ "C: \ documents and settings \ all users \ desktop", "*. TXT");
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
Private void hide toolstripmenuitem [click (object sender, EventArgs E)
{
panel1.Hide();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
string name = a[listBox1.SelectedIndex];
using (FileStream file = new FileStream(name, FileMode.OpenOrCreate, FileAccess.Read))
{
byte[] bytes = new byte[1024 * 1024 * 5];
int r = file.Read(bytes, 0, bytes.Length);
this.textBox1.Text = Encoding.Default.GetString(bytes, 0, r);
}
this.textBox2.Text = a[listBox1.SelectedIndex];
}
private void button1_Click(object sender, EventArgs e)
{
string pat = this.textBox2.Text;
//File.Delete(pat);
}
}
} 





C # Notepad


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.