zoukankan      html  css  js  c++  java
  • 窗体-对话框,记事本

    对话框确认和取消选项:

    Dialogresult dr=Messbox.show("确定","确定要改?",MessboxBoxButtons.OKCancl);

    if(dr==Dialogresult.OK)

    {

       //事件

    记事本打开文本文档:

    private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
    {
    openFileDialog1.Filter = "文本文件|*.txt";
    DialogResult dr = openFileDialog1.ShowDialog();
    if (dr == DialogResult.OK)
    {
    string s = openFileDialog1.FileName;
    StreamReader sr = new StreamReader(s, Encoding.Default);
    textBox1.Text = sr.ReadToEnd();
    string[] ss = s.Split('\');
    this.Text = ss[ss.Length - 1] + "-记事本";
    }
    }

    保存:

    private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e)
    {
    saveFileDialog1.Filter = "文本文件|*.txt";
    saveFileDialog1.FileName = "文本文档|*.txt";
    DialogResult dr = saveFileDialog1.ShowDialog();
    if (dr == DialogResult.OK)
    {
    string s = saveFileDialog1.FileName;
    StreamWriter sw = new StreamWriter(s);
    sw.Write(textBox1.Text);
    sw.Flush();
    }
    }

    打印:          

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
    string s = textBox1.Text;
    Font f = new System.Drawing.Font("宋体", 24);
    Brush b = new SolidBrush(Color.Green);
    e.Graphics.DrawString(s, f, b, 10, 10);

    ------------------------------------------------------------------------------//设置打印的对象

    private void toolStripMenuItem1_Click(object sender, EventArgs e)
    {
    pageSetupDialog1.Document = printDocument1;  //每个方法都要设置打印的对象,为 printDocument1,事件中选择printPage
    DialogResult dr = pageSetupDialog1.ShowDialog();
    if (dr == DialogResult.OK) { }
    }

    -----------------------------------------------------------------------------//设置页面

    private void 打印PToolStripMenuItem_Click(object sender, EventArgs e)
    {
    printDialog1.Document = printDocument1;
    DialogResult dr = printDialog1.ShowDialog();
    if (dr == DialogResult.OK)
    {
    printDocument1.Print();
    }
    }

    ------------------------------------------------------------------------------//打印选项,比如选择打印机

    private void 打印预览VToolStripMenuItem_Click(object sender, EventArgs e)
    {
    printPreviewDialog1.Document = printDocument1;
    printPreviewDialog1.Show();
    }

    ------------------------------------------------------------------------------//打印预览

  • 相关阅读:
    无废话WPF系列9: Binding的源
    无废话WPF系列7:WPF布局控件
    无废话WPF系列6:各类控件家族详解
    无废话WPF系列13:路由事件
    无废话WPF系列4: x名称空间
    无废话WPF系列12: 依赖属性和附加属性
    用C++设计一个不能被继承的类
    HMM的介绍及实现
    C语言综合实验3—计算器四则运算
    机器学习基础
  • 原文地址:https://www.cnblogs.com/m110/p/7902561.html
Copyright © 2011-2022 走看看