- 定义
PictureBox 控件可以显示来自位图、图标或者元文件,以及来自增强的元文件、JPEG 或 GIF 文件的图形。如果控件不足以显示整幅图象,则裁剪图象以适应控件的大小。
2练习-图片的切换
(1)新建
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e40183e562b0d224a7a37f542446fe10.png#pic_center)
(2)程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace _10实现照片的上一张下一张翻页效果
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Image = Image.FromFile(@"C:\Users\SpringRain\Desktop\Picture\1.jpg");
}
int i = 0;
string[] path = Directory.GetFiles(@"C:\Users\SpringRain\Desktop\Picture");
private void button2_Click(object sender, EventArgs e)
{
i++;
if (i == path.Length)
{
i = 0;
}
pictureBox1.Image = Image.FromFile(path[i]);
}
private void button1_Click(object sender, EventArgs e)
{
i--;
if (i < 0)
{
i = path.Length - 1;
}
pictureBox1.Image = Image.FromFile(path[i]);
}
}
}