OpenFileDialog

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、成都做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的中原网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

namespace WindowsFormsApp4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)//读取文本
    {
        this.openFileDialog1.Filter = "*.txt|*.txt";
        if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            StreamReader sr = new StreamReader(openFileDialog1.FileName);
            MessageBox.Show(sr.ReadToEnd());
            sr.Close();
        }
    }

    private void button2_Click(object sender, EventArgs e)//选择图片
    {
        this.openFileDialog1.Filter = "(*.jpg;*.jpg;*.jpeg;*.gif;*.png)|*.jpg;*.jpeg;*.gif;*.png";
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            MessageBox.Show("" + openFileDialog1.FileName);
            pictureBox1.ImageLocation = openFileDialog1.FileName;

        }

    }
    //拷贝到制定文件夹
    private void button4_Click(object sender, EventArgs e)
    {
        string oldpath = pictureBox1.ImageLocation;
        string fileName = System.IO.Path.GetFileName(oldpath).ToString();
        string copypath = System.IO.Directory.GetCurrentDirectory() + "/images/";//当前运行程序的images文件夹
        if (!Directory.Exists(copypath))//如果这个目录不存在就创建
        {
            Directory.CreateDirectory(copypath);
        }

        File.Copy(pictureBox1.ImageLocation, copypath + fileName, true);
        MessageBox.Show("保存成功");
    }

    //另存
    private void button3_Click(object sender, EventArgs e)
    {
        SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        string oldpath = pictureBox1.ImageLocation;
        string fileName = System.IO.Path.GetFileName(oldpath).ToString();
        string houzui = System.IO.Path.GetExtension(oldpath).ToString();
        saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
        saveFileDialog1.FilterIndex = 2;
        saveFileDialog1.RestoreDirectory = true;

        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {
                MessageBox.Show(saveFileDialog1.FileName);

                File.Copy(pictureBox1.ImageLocation, saveFileDialog1.FileName+houzui, true);
        }
    }

}

}


网站标题:OpenFileDialog
文章来源:http://bzwzjz.com/article/gpdpcp.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 企业网站建设 营销型网站建设 专业网站设计 成都网站制作 成都网站制作 网站建设推广 做网站设计 成都企业网站制作 成都商城网站建设 营销网站建设 成都商城网站制作 重庆网站建设 手机网站制作 网站设计制作报价 网站制作 成都响应式网站建设 营销型网站建设 达州网站设计 成都网站建设 高端定制网站设计 重庆企业网站建设 网站设计