如题:这是错误代码提示: 未处理 System.NullReferenceException 程序代码: /// 定义一个资源管理器 private ResourceManager rm; private static string Skin_Path = Environment.CurrentDirectory + “\Skin\”;//皮肤文件夹路径 protected override void OnPaint(PaintEventArgs e) 就在有颜色地方报错的,急需解决方法,再次谢谢大虾。 |
|
谢谢大家,在没有高人回答钱,希望大家顶顶,不要让帖子沉了。
|
|
Brush brush = new TextureBrush(Top_Left, new Rectangle(0, 0, Top_Left.Width, Top_Left.Height));
Top_Left的值是null的,if (!System.IO.File.Exists(“skin.Resource”))这后边的语句如果没执行,就没对Top_Left初始化 |
|
5分 |
应该是没进去条件 |
//背景图片拆分 private static Bitmap tl = Properties.Resources.Top_Left; private static Bitmap tm = Properties.Resources.Top_Middle; private static Bitmap tr = Properties.Resources.Top_Right; private static Bitmap ml = Properties.Resources.Middle_Left; private static Bitmap mm = Properties.Resources.Middle_Content; private static Bitmap mr = Properties.Resources.Middle_Right; private static Bitmap bl = Properties.Resources.Bottom_Left; private static Bitmap bm = Properties.Resources.Bottom_Middle; private static Bitmap br = Properties.Resources.Bottom_Right; //重绘窗体背景 private void FormPaint(object sender, System.Windows.Forms.PaintEventArgs e) { //重绘左上角 e.Graphics.DrawImage(tl, 0, 0, tl.Width, tl.Height); //重绘上方中间 TextureBrush brush = new TextureBrush(tm, new Rectangle(0, 0, tm.Width, tm.Height)); e.Graphics.FillRectangle(brush, tl.Width, 0, Width - tl.Width - tr.Width, tm.Height); //重绘右上角 e.Graphics.DrawImage(tr, Width - tr.Width, 0, tr.Width, tr.Height); //重绘左边框 brush = new TextureBrush(ml); e.Graphics.FillRectangle(brush, 0, tl.Height, ml.Width, Height - tl.Height - bl.Height); //重绘中间背景 brush = new TextureBrush(mm); e.Graphics.FillRectangle(brush, ml.Width, tl.Height, Width - ml.Width - mr.Width, Height - tl.Height - bl.Height); //重绘右边框 brush = new TextureBrush(mr); brush.TranslateTransform(Width - mr.Width, tr.Height);//把偏移量补偿回来 e.Graphics.FillRectangle(brush, Width - mr.Width, tl.Height, mr.Width, Height - tr.Height - br.Height); //重绘左下角 e.Graphics.DrawImage(bl, 0, Height - bl.Height, bl.Width, bl.Height); //重绘下方中间 brush = new TextureBrush(bm); brush.TranslateTransform(bl.Width, Height - bm.Height);//把偏移量补偿回来 e.Graphics.FillRectangle(brush, bl.Width, Height - bm.Height, Width - bl.Width - br.Width, bm.Height); //重绘右下角 e.Graphics.DrawImage(br, Width - br.Width, Height - br.Height, br.Width, br.Height); } 那个判断直接跳过了,所以没有初始化Top_Left |
|
5分 |
未将对象引用到实例化,就是你引用了为实例化的对象,对象你空的,你这里应该就是Top_Left,他应该是一个Image的对象。
|
30分 |
rm = new ResourceManager(“SkinWindow.Skin”, this.GetType().Assembly);
Top_Left = (Image)rm.GetObject(“Top_Left.png”); 改为如下方式就OK了 ResourceSet rs = new ResourceSet(“skin.resource”); Top_Left = (Image)rs.GetObject(“Top_Left.png”); |