溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

OpenFileDialog

發(fā)布時間:2020-07-22 18:55:02 來源:網絡 閱讀:685 作者:趙秋陽 欄目:軟件技術

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))//如果這個目錄不存在就創(chuàng)建
        {
            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);
        }
    }

}

}

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI