Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

OpenFileDialog

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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) / / read text {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) / / Select the picture {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;}} / / copy to the formulation folder 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 folder if (! Directory.Exists (copypath)) / / create {Directory.CreateDirectory (copypath) if this directory does not exist;} File.Copy (pictureBox1.ImageLocation, copypath + fileName, true); MessageBox.Show ("saved successfully") } / / Save 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);}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report