2013-02-28 89 views
1

我想为我的按钮设置一个背景图像。我的背景图片没有出现在按钮上。所以我决定登录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 
+0

它看起来不像你需要在运行时做到这一点;你有没有尝试过在运行时通过属性窗口设置它? – tmwoods 2013-02-28 05:12:01

回答

2

BackgroundImage属性是指向一个Image对象,initialy是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()); 
相关问题