Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想为我的按钮设置背景图像。我的背景图片没有出现在按钮上。所以我决定记录 myButton。
this->myButton->BackgroundImage->FromFile( "c:\\red\\Desert.jpg"); myLog(this->myButton->BackgroundImage->ToString());
记录字符串时发生崩溃:
message Object reference not set to an instance of an object
BackgroundImage 属性是一个指向 Image 对象的指针,最初它是 nullptr,因此您试图从不存在的对象访问方法。正确的代码可能是这样的:
this->myButton->BackgroundImage = Image::FromFile("c:\\red\\Desert.jpg"); // Now the image object is initialized and you can log it myLog(this->myButton->BackgroundImage->ToString());