Tải bản đầy đủ (.doc) (5 trang)

Tài liệu Lập trình C# - Code đăng nhập pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (35.17 KB, 5 trang )

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace BAIBACCAO
{
public partial class notepad : Form
{
public notepad()
{
InitializeComponent();
}
String filename = "";

private void deleteToolStripMenuItem_Click(object sender,
EventArgs e)
{
txtnoidung.Clear();
}
private void newToolStripMenuItem_Click(object sender, EventArgs
e)
{
txtnoidung.Text = "";
this.Text = "Untitled";
filename = "";
}
private void openToolStripMenuItem_Click(object sender,


EventArgs e)
{
openFileDialog1.Filter = "Text Files (*.txt)|*.txt|Word
Documents" +
"(*.doc)|*.doc|All Files (*.*)|
*.*";
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
filename = openFileDialog1.FileName;
this.Text = filename;
StreamReader strReader;// bien dung de doc du lieu
ra
strReader = File.OpenText(filename);
txtnoidung.Text = strReader.ReadToEnd();
strReader.Close();
}
}
catch
{
MessageBox.Show("Lỗi chương trình ?");
}

}
private void saveToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (filename == "")
{

saveFileDialog1.Filter = "Text Files (*.txt)|*.txt|Word
Documents" +
"(*.doc)|*.doc|All Files (*.*)|
*.*";
saveFileDialog1.FileName = "Untitled";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
//'Luu noi dung
filename = saveFileDialog1.FileName;
FileStream fStream;//chua ten moi
StreamWriter strWriter;//dung doc
fStream = File.Create(filename);
fStream.Close();
strWriter = File.AppendText(filename);
strWriter.Write(txtnoidung.Text);
strWriter.Close();
this.Text = filename;
}
}
else
{
//'Luu noi dung
FileStream fStream;
StreamWriter strWriter;
fStream = File.Create(filename);
fStream.Close();
strWriter = File.AppendText(filename);
strWriter.Write(txtnoidung.Text);
strWriter.Close();
this.Text = filename;

}
}
private void saveAsToolStripMenuItem_Click(object sender,
EventArgs e)
{
saveFileDialog1.Filter = "Text Files (*.txt)|*.txt|Word
Documents" +
"(*.doc)|*.doc|All Files (*.*)|
*.*";
saveFileDialog1.FileName = "Untitled";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
filename = saveFileDialog1.FileName;
FileStream fStream; //bien chua ten file can tao de
luu
StreamWriter strWriter; //bien dung de ghi du lieu
vao
fStream = File.Create(filename);
fStream.Close(); //tao song roi dong lai
strWriter = File.AppendText(filename); //gan noi dung
vao cho bien
strWriter.Write(txtnoidung.Text); //thuc hien ghi
strWriter.Close();
}
}
private void exitToolStripMenuItem_Click(object sender,
EventArgs e)
{
Close();
}

private void notepad_Load(object sender, EventArgs e)
{
txtnoidung.Size = new Size(this.ClientRectangle.Width - 4,
this.ClientRectangle.Height - 28);
txtnoidung.Location = new Point(2, 26);

}
private void notepad_Resize(object sender, EventArgs e)
{
txtnoidung.Size = new Size(this.ClientRectangle.Width - 4,
this.ClientRectangle.Height - 28);
txtnoidung.Location = new Point(2, 26);
}
private void unduToolStripMenuItem_Click(object sender,
EventArgs e)
{
txtnoidung.Undo();
}
private void cutToolStripMenuItem_Click(object sender, EventArgs
e)
{
txtnoidung.Cut();
}
private void pastToolStripMenuItem_Click(object sender,
EventArgs e)
{
txtnoidung.Paste();
}
private void copyToolStripMenuItem_Click(object sender,
EventArgs e)

{
txtnoidung.Copy();
}
private void selectAllToolStripMenuItem_Click(object sender,
EventArgs e)
{
txtnoidung.SelectAll();
}
private void dataTimeToolStripMenuItem_Click(object sender,
EventArgs e)
{
System.DateTime currentTime = System.DateTime.Now;
txtnoidung.Text = txtnoidung.Text + " " + DateTime.Now;

}
private void fontToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
txtnoidung.Font = fontDialog1.Font;
}

}
private void fontcolorToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
txtnoidung.ForeColor = colorDialog1.Color;

}
}

private void backGoundToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
txtnoidung.BackColor = colorDialog1.Color;
}
}
private void wordWrapToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (wordWrapToolStripMenuItem.Checked)
{
txtnoidung.WordWrap = true;
txtnoidung.ScrollBars = ScrollBars.Vertical;
}
else
{
txtnoidung.WordWrap = false;
txtnoidung.ScrollBars = ScrollBars.Both;
}
}
private void saveWithKeyToolStripMenuItem_Click(object sender,
EventArgs e)
{
//MessageBox.Show("Nhóm em chưa làm được ?");
}

private void menuStrip1_ItemClicked(object sender,
ToolStripItemClickedEventArgs e)
{
}

}
}

×