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

  • 相关阅读:
    003 Leaflet 第三个demo 地图上的面积测量
    002 Leaflet 第二个demo 地图上的矩形拉框选择
    001 Leaflet 第一个demo 加载天地图
    This关键字,打印花瓣的数量
    Myeclipse8.5 添加Tomcat7
    WGS84经纬度 与 web 墨卡托相互转化 工具类
    java list集合去重复
    response 下载文件
    jquery实现可拖拽的div
    linux 前端环境搭建
  • 原文地址:https://www.cnblogs.com/woshare/p/2767319.html
Copyright © 2011-2022 走看看