码迷,mamicode.com
首页 > 其他好文 > 详细

记事本 对话框

时间:2015-11-11 19:12:09      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

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();
        }
    }
}

  

记事本 对话框

标签:

原文地址:http://www.cnblogs.com/ROCKyou/p/4956762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!