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不知道是什么组件?

  • 相关阅读:
    js用8421码实现10进制转2进制
    什么?toggle(fn1, fn2)函数在1.9版本jq被移除? 来来来,自己撸一个
    js获取鼠标点击的对象,点击另一个按钮删除该对象
    html5小结
    iphone状态栏高度?
    制作手机相册 全屏滚动插件fullpage.js
    js 相关知识整理(一)
    css 居中问题
    进度条
    @Html.Raw()
  • 原文地址:https://www.cnblogs.com/woshare/p/2767319.html
Copyright © 2011-2022 走看看