public partial class Form1 : Form
    {
        private class 图片列表
        {
          
           public static int 图像宽度=48;
           public  static int 图像长度=64;
           public Image 项目图像;   
           public string 字符项目;            public static int 图像宽度属性
            {
                get
                {
                    return 图像宽度;
                }                set
                {
                    图像宽度 = 48;
                }
            }            public static int 图像长度属性
            {
                get 
                {
                    return 图像长度;
                }
                set
                {
                    图像长度 = 64;
                }
            }            public Image 项目图像属性
            {
                get 
                {
                    return 项目图像;
                }
                set
                {
                    项目图像 = null;
                }
            }
            public string 字符项目属性
            {
                get
                {
                    return 字符项目;
                }
                set
                {
                    字符项目 = "";
                }
            }        }
        public Form1()
        {
            InitializeComponent();
            listBox1 .ItemHeight = 图片列表.图像长度属性 + 2;
        }        private void Form1_Load(object sender, EventArgs e)
        {
            图片列表[] 我的图像 = new 图片列表[8];
            我的图像[0].项目图像属性 = _138赵志华高手版.Properties.Resources.蔡依林;
            我的图像[0].字符项目属性 = "蔡依林";
           
            我的图像[1].项目图像属性 = _138赵志华高手版.Properties.Resources.陈德容;
            我的图像[1].字符项目属性 = "陈德容";            我的图像[2].项目图像属性 = _138赵志华高手版.Properties.Resources.陈慧琳;
            我的图像[2].字符项目属性 = "陈慧琳";            我的图像[3].项目图像属性 = _138赵志华高手版.Properties.Resources.温碧霞;
            我的图像[3].字符项目属性 = "温碧霞";            我的图像[4].项目图像属性 = _138赵志华高手版.Properties.Resources.徐静蕾;
            我的图像[4].字符项目属性 = "徐静蕾";            我的图像[5].项目图像属性 = _138赵志华高手版.Properties.Resources.徐若宣;
            我的图像[5].字符项目属性 = "徐若瑄";            我的图像[6].项目图像属性 = _138赵志华高手版.Properties.Resources.张柏芝;
            我的图像[6].字符项目属性 = "张柏芝";            我的图像[7].项目图像属性 = _138赵志华高手版.Properties.Resources.张曼玉;
            我的图像[7].字符项目属性 = "张曼玉";            foreach (图片列表 itm in 我的图像)
            {
                listBox1.Items.Add(itm);
            }
        }        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
                return;
            Graphics g = e.Graphics;
            Rectangle re = listBox1.GetItemRectangle(e.Index);
            re.X += 1;
            re.Y += 1;
            re.Height = 图片列表.图像长度;
            re.Width = 图片列表.图像宽度;
            图片列表 my = (图片列表)listBox1.Items[e.Index];
            g.DrawImage(my.项目图像属性, re);
            g.DrawString(my.字符项目属性, new Font("方正字迹-童体硬笔字体", 36),
                Brushes.Red, re.X + 图片列表.图像宽度属性 + 4, re.Y + 8);
            re = listBox1.GetItemRectangle(e.Index);
            re.Width -= 1;
            re.Height -= 1;
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                g.DrawRectangle(Pens.Red, re);
            else
                g.DrawRectangle(Pens.LightGray, re);
        }        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            图片列表 my = (图片列表)listBox1.Items[listBox1.SelectedIndex];
           namelabel .Text = my.字符项目属性;
           pictureBox1.Image = my.项目图像属性;
        }
    }
代码都子啊这了,出错的就在红色部分,报错信息是
未处理的“System.NullReferenceException”类型的异常出现在 138赵志华高手版.exe 中。
其他信息: 未将对象引用设置到对象的实例。

解决方案 »

  1.   

    _138赵志华高手版.Properties.Resources.蔡依林;在你的资源文件中有吗?
    你点.运算符有提示吗?
      

  2.   

    空指针
     _138赵志华高手版.Properties.Resources.蔡依林;有空对象
      

  3.   

    可以直接说吗? _138赵志华高手版.Properties.Resources.蔡依林;这个属于什么?怎么有空对象?那错误是出在哪了?
      我的图像[0].项目图像属性 =这有错还是这_138赵志华高手版.Properties.Resources.蔡依林;
      

  4.   

    也就是说“_138赵志华高手版.Properties.Resources.蔡依林"不存在,你直接调用看看