我正在使用此代码获取图像并以pictureboxes
特定的子表单显示它们,我将为另外 4 5 个子表单做同样的事情,但我不希望这些图像在任何表单或图片框中重复,我怎样才能做到这一点 ?在每个表格上我都有 3pictureboxes
public partial class MainForm : Form
{
string LoginName;
List<PictureBox> pictureBoxes;
List<String> filesToShow = new List<String>();
public MainForm(string lognName)
{
InitializeComponent();
this.LoginName = lognName;
pictureBoxes = new List<PictureBox> {
pictureBox1,
pictureBox2,
pictureBox3
};
ShowImages();
}
private List<String> GetFilesToShow()
{
String str = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string path = str + "\\Image\\";
return Directory.GetFiles(path, "*.jpg", SearchOption.TopDirectoryOnly).ToList();
}
private void ShowImages()
{
List<int> selectedImages = new List<int>();
foreach (var pictureBox in pictureBoxes)
{
if (filesToShow != null && !filesToShow.Any())
{
filesToShow = GetFilesToShow();
}
if (filesToShow != null && filesToShow.Any()) // If any files then allow the code to delete the shown images
{
if (filesToShow.Count >= pictureBoxes.Count)
{
filesToShow.Reverse();
for (int i = 1; i < 4; i++)
{
pictureBox.ImageLocation = filesToShow[i];
}
}
}
}
}
}