新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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);
}
}
}
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。