设置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);
}
}
}