zoukankan      html  css  js  c++  java
  • OpenFileDialog .

    OpenFileDialog 组件可以浏览本机或网络中任何计算机上的文件夹,并选择打开一个或多个文件,返回用户在对话框中选定的文件的路径和名称。

    用户选定要打开的文件后,可以使用两种机制来打开文件。

    如果希望使用文件流,则可以创建 StreamReader 类的实例。另一种方法是使用 OpenFile 方法打开选定的文件。

    示例1

    private void button1_Click(object sender, System.EventArgs e)
    {
    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    System.IO.StreamReader sr = new
    System.IO.StreamReader(openFileDialog1.FileName);
    MessageBox.Show(sr.ReadToEnd());
    sr.Close();
    }
    }

    在窗体的构造函数中放置以下代码,以注册事件处理程序。

    this.button1.Click += new System.EventHandler(this.button1_Click);

    示例2

    private void btnBrowse_Click(object sender, EventArgs e)

    {

    OpenFileDialog OpenPhotoFileDialog = new OpenFileDialog();

    OpenPhotoFileDialog.Filter = "jpg files (*.jpg)|*.jpg|bmp files(*.bmp)|*.bmp|png files (*.png)|*.png|All files (*.*)|*.*";

    OpenPhotoFileDialog.ShowDialog();

    if (OpenPhotoFileDialog.FileName.Trim() != "")

    {

    this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

    this.pictureBox1.ImageLocation = OpenPhotoFileDialog.FileName;

    this.txtPhotoFilePath.Text = OpenPhotoFileDialog.FileName;

    }

    }

    示例3


    private void button1_Click(object sender, System.EventArgs e)
    {
    // Displays an OpenFileDialog so the user can select a Cursor.
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "Cursor Files|*.cur";
    openFileDialog1.Title = "Select a Cursor File";
    // Show the Dialog.
    // If the user clicked OK in the dialog and
    // a .CUR file was selected, open it.
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    // Assign the cursor in the Stream to the Form's Cursor property.
    this.Cursor = new Cursor(openFileDialog1.OpenFile());
    }
    }

    在窗体的构造函数中放置以下代码,以注册事件处理程序。

    this.button1.Click += new System.EventHandler(this.button1_Click);

    看了这篇文章,但是还是不知道openfileDialog不知道是什么组件?

  • 相关阅读:
    Golang error 的突围
    深度解密Go语言之 scheduler
    深度解密Go语言之channel
    如何打造一份优雅的简历?
    Go 程序是怎样跑起来的
    曹大谈内存重排
    从零开始使用 Webpack 搭建 Vue 开发环境
    纯样式无脚本无图片自定义单/复选框
    从零开始使用 Webpack 搭建 Vue3 开发环境
    JS遍历对象的几种方法
  • 原文地址:https://www.cnblogs.com/woshare/p/2767319.html
Copyright © 2011-2022 走看看