自動建立資料夾 pictureBox 顯示圖片 並呼叫系統窗體開啟資料夾
阿新 • • 發佈:2018-12-21
設定pictureBox1 圖片自適應:
SizeMode:StretchImage
BackgroundImagelayout : Stretch;
點選開啟檔案效果如下:
程式碼實現:
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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static string path = "d:\\robot\\images"; //圖片路徑 private void Form1_Load(object sender, EventArgs e) { if (!Directory.Exists("d:\\robot\\images"))//若資料夾不存在則新建資料夾 { Directory.CreateDirectory("d:\\robot\\images"); //新建資料夾 } pictureBox1.BackgroundImage = Image.FromFile(path + "\\sh.png"); } private void btn_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start(path); } } }