namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult dr = colorDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
this.BackColor = colorDialog1.Color;
}
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult dr = folderBrowserDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
MessageBox.Show(folderBrowserDialog1.SelectedPath);
}
else
{
MessageBox.Show(folderBrowserDialog1.SelectedPath);
}
}
private void button3_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
MessageBox.Show(fontDialog1.Font.Size.ToString());
}
private string Files;
private void button4_Click(object sender, EventArgs e)
{
DialogResult dr = openFileDialog1.ShowDialog();
if (DialogResult.OK == dr)
{
string filename = openFileDialog1.FileName;
StreamReader sr = new StreamReader(filename);
textBox1.Text = sr.ReadToEnd();
sr.Close();
Files = filename;
}
}
private void button5_Click(object sender, EventArgs e)
{
if (Files == null)
{
saveFileDialog1.Filter = "文本 |*.txt|word|*.doc|excel|*.xls";
DialogResult dr = saveFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;
StreamWriter sw = new StreamWriter(filename);
sw.Write(textBox1.Text);
sw.Close();
}
}
else
{
StreamWriter sw = new StreamWriter(Files);
sw.Write(textBox1.Text);
sw.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
this.Close();
}
private void button7_Click(object sender, EventArgs e)
{
pageSetupDialog1.Document = printDocument1;
pageSetupDialog1.ShowDialog();
}
private void button8_Click(object sender, EventArgs e)
{
printDialog1.Document = printDocument1;
DialogResult dr = printDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
System.Drawing.Font f = new System.Drawing.Font("宋体",12);
e.Graphics.DrawString(textBox1.Text,f,System.Drawing.Brushes.Aqua,5,5);
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.SelectedText = "asd";
}
private void button10_Click(object sender, EventArgs e)
{
FirstForm.Find f = new FirstForm.Find(this.textBox1.SelectedText,this);
f.Owner = this;
f.Show();
}
}
}