在C#中,我想用button按钮来实现picturebox控件的随机选图,我想在D:\数字密码 中随机选图片 5
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace WinFormRandomPic
{
public partial class Form1 : Form
{
private readonly string PicDir = @"D:\数字密码\";
private List<string> picFiles;
public Form1()
{
InitializeComponent();
picFiles = new List<string>();
picFiles.AddRange(Directory.GetFiles(PicDir, "*.jpg"));
picFiles.AddRange(Directory.GetFiles(PicDir, "*.bmp"));
picFiles.AddRange(Directory.GetFiles(PicDir, "*.png"));
}
private void button1_Click(object sender, EventArgs e)
{
Random rd = new Random();
int index = rd.Next(0, picFiles.Count);
pictureBox1.Image = Image.FromFile(picFiles[index]);
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询