zoukankan      html  css  js  c++  java
  • 对话框

    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 对话框
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
               // openFileDialog1.Filter = "文本文件|(*.txt)|所以文件|*.*|视频文件|*.avi";//每两个是一组,筛选文件后缀名
                openFileDialog1.Filter = "视频文件|*.avi;*.mp4;*.mp3;*.txt;*.jpg";//多个需要用";"隔开
                //openFileDialog1.ShowDialog();//显示对话框
                DialogResult isok = openFileDialog1.ShowDialog();//枚举返回鼠标点击的选项值
                if (isok==DialogResult.OK)//判断是否点的确定按钮
                {
                    string s = openFileDialog1.FileName;//获取选中的文件的文件路径
                    //MessageBox.Show(s);
                    //使用流进行文件读取
                    StreamReader sr = new StreamReader(s,Encoding.Default);//读取文件路径的文件,设置编码方式
                    textBox1.Text = sr.ReadToEnd();
                    sr.Close();//用完流必须关掉,不然其他地方没法写流,会一直被占用
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                saveFileDialog1.Filter = "文本文件|*.txt";
                DialogResult isok = saveFileDialog1.ShowDialog();
                if (isok==DialogResult.OK)
                {
                    string s = saveFileDialog1.FileName;
                    //使用流保存   //流是程序和硬盘之间的通道,路径就是硬盘上的地址,打通一个通道,按这个地址
                    //去读取内容或者存储内容
                    StreamWriter sw = new StreamWriter(s);//创建一个缓存区,在这个路径下存储文本内容
                    sw.Write(textBox1.Text);//把文本内容写入这个路径存储区
                    sw.Close();//关闭流
                }
    
            }
        }
    }
  • 相关阅读:
    uvm_reg_map——寄存器模型(八)
    uvm_reg_block——寄存器模型(七)
    mysql_secure_installation 安全安装(用于生产环境设置)
    一键安装nginx-1.12.2
    nginx优化之隐藏版本号
    shell script 之六:循环 while
    shell script 之五:循环控制 for
    shell script 之四:流程控制 if 分支语句
    shell script 之三:打印输出 echo printf
    shell script 之一:变量和赋值
  • 原文地址:https://www.cnblogs.com/happinesshappy/p/4541102.html
Copyright © 2011-2022 走看看