使用属性时出现问题.资源类



我有一个XO游戏。它需要三张图片:X、O和?。当图片在exe浴缸附近时,程序运行得很好。当我将三张图片添加到资源中时,我有一个空异常:

private Bitmap xImage;
private Bitmap oImage;
private Bitmap initImage;

该代码在构造函数中:

// old code
this.xImage = new Bitmap(Application.StartupPath + "\x.jpg");
// works well
// new code
this.xImage = new Bitmap(Properties.Resources.XImage);
// Null reference exception is thrown here

检查图像是否真的在资源文件中。双击项目中的Resources.resx文件,从左上角选择"Images",并验证这三个图像是否存在,其中一个图像是否命名为"XImage"。如果它们不存在,请尝试重新添加它们。如果它们的名称错误,您可以右键单击它们来重命名它们。

代码看起来是正确的。

最新更新