C# 未将对象引用设置到对象的实例 怎么改?
请各位大神指点,调试的时候总是在加红的那2行出现“未将对象引用设置到对象的实例”的提示。应该怎么改啊?namespace 界面1
{
public delegate void ChangeImageHandler(String message);
public partial class Form4 : Form
{
private ShowPic _ShowPic;
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
_ShowPic = new ShowPic(pictureBox1);
_ShowPic.ChangeImage += new ChangeImageHandler(ChangeImage);
_ShowPic.Load(@"E:\2\现场图片\1", SearchOption.TopDirectoryOnly);
}
private void label2_Click(object sender, EventArgs e)
{
_ShowPic.Last();
}
private void label3_Click(object sender, EventArgs e)
{
_ShowPic.Next();
}
private void ChangeImage(String message)
{
this.Text = message;
}
private void Form4_FormClosing(object sender, FormClosingEventArgs e)
{
if (_ShowPic != null)
{
_ShowPic = null;
}
}
}
public sealed class ShowPic
{
public event ChangeImageHandler ChangeImage;
private String[] _ArrPicPath;
private Int32 _Index;
private PictureBox _PictureBox;
private void OnChangeImage(String message)
{
ChangeImageHandler temp = (ref ChangeImage, null, null);
if (temp != null)
{
temp(message);
}
}
public ShowPic(PictureBox pictureBox)
{
_PictureBox = pictureBox;
_Index = 0;
}
public void Load(String path, SearchOption searchOption)
{
if (!Directory.Exists(path))
{
OnChangeImage(path + " 路径不存在");
throw new DirectoryNotFoundException(path + " 路径不存在");
}
_ArrPicPath = (path,"*.jpg", searchOption);
LoadImage();
}
public void Last()
{
lock (_ArrPicPath)
{
if (_Index > 0)
{
_Index--;
}
else
{
OnChangeImage("已经是第一张");
return;
}
}
LoadImage();
}
public void Next()
{
lock (_ArrPicPath)
{
if (_Index < _ArrPicPath.Length - 1)
{
_Index++;
}
else
{
OnChangeImage("已经是最后一张");
return;
}
}
LoadImage();
}
private void LoadImage()
{
if (_ArrPicPath == null || _ArrPicPath.Length <= 0)
{
OnChangeImage("没有图片");
return;
}
String path = _ArrPicPath[_Index];
if (File.Exists(path))
{
_PictureBox.Load(path);
OnChangeImage(path);
}
}
}
}
本人新手,还没有分可给,不好意思!