Embedded image issues.

  • Thread starter Thread starter HotIndigo
  • Start date Start date
H

HotIndigo

Guest
Hello all,
I'm relatively new to c++, my main language being VB.
My goal is to have a picturebox (pic_Swap) whose image changes when the mouse goes over it and restores to the original when the mouse has left. With VB one can use embedded resource images very easily, but I have hit a brick wall with c++!
My initial attempts resulted in having to use 2 hidden picture boxes (pic_In & pic_Out with the appropriate images embedded) and copying their Image files to pic_Swap.
In the InitializeComponent section I used:

void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(mySwapper::typeid));
//// ... removed unnecessary code...
//
// pic_In
//
this->pic_In->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pic_In.Image")));
//
// pic_Out
//
this->pic_Out->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pic_Out.Image")));



and for the mouse handlers for the image swap:

private: System::Void pic_Swap_MouseEnter(System::Object^ sender, System::EventArgs^ e) {
this->pic_Swap->Image = this->pic_In->Image;
}
private: System::Void pic_Swap_MouseLeave(System::Object^ sender, System::EventArgs^ e) {
this->pic_Swap->Image = this->pic_Out->Image;
}


The result was I kept getting this error message on theresources->GetObject(L"pic_In.Image") line:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MyProject.mySwapper.resources" was correctly embedded or linked into assembly "mySwapper" at compile time, or that all the satellite assemblies required are loadable and fully signed.

After much more searching, I tried this (without using pic_In or pic_Out):

private: System::Void pic_Swap_MouseEnter(System::Object^ sender, System::EventArgs^ e) {
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(mySwapper::typeid));
this->pic_Swap->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pic_In.Image")));
}


The result is, again, the same resource error message as above. Is there any (relatively) simple way to use embedded images to achieve the desired image swap? My ideal aim is not to have to use the "artifice" of copying images from the pic_In & pic_Out pictureboxes (which I have to hide during initialisation!).

P.S. I have kept the code to the bare minimum - if more is required please ask.

TIA.

Continue reading...
 
Back
Top