理想的には、1 つの画像を非表示にして他の画像を表示するのではなく、バッファ ロジックを作成する必要があります。画像を表示する前に画像をロードするいくつかのバッファを用意し、画像ごとに新しいセットを設定するよりも、画像を表示する実際のフィールドの数を固定する方がはるかに良い考えです。
ただし、ソリューションでそれが必要な場合は、カスタム ユーザー コントロールを作成してみてください。
次のようなことを試してください:
public class customUserControl : UserControl
{
//Store image as a Uri rather than an Image
private Uri StoredImagePath;
public class PictureBoxAdv : PictureBox
{
public PictureBoxAdv()
{
this.VisibleChanged +=new EventHandler(VisibleChanged);
}
}
public Uri Image
{
get { return StoredImagePath; }
set
{
StoredImagePath = value;
if (this.Visible && StoredImagePath != null)
{
this.Image = Image.FromFile(StoredImagePath.AbsolutePath);
}
}
}
public void VisibleChanged(object sender, EventArgs e)
{
//When becomes visible, restore image, invisible, nullify.
if (this.Visible && StoredImagePath != null)
{
this.Image = Image.FromFile(StoredImagePath.AbsolutePath);
}
else
{
this.Image = null;
}
}
}