记事本 对话框

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

  

转载于:https://www.cnblogs.com/ROCKyou/p/4956762.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值