So I am very new to GUI’s and tried to learn and build a simple one with Visual Studio using the (.Net framework). It is a login that opens another form when the login is successful. I used an image from the computer as a background for the login form and tried to use it for the other form. I get "System.Resources.MissingManifestResourceException:" exception when trying to run the UI.
It also appears in the code where I used a picturebox to place an image from my computer in the same form.
This is the code for background:
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage"))); // exception appears here //
this->ClientSize = System::Drawing::Size(660, 390);
this->Controls->Add(this->button7);
this->Controls->Add(this->button6);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);
Code for imagebox:
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.Image"))); //appears here //
this->pictureBox1->Location = System::Drawing::Point(73, 130);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(162, 141);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pictureBox1->TabIndex = 22;
this->pictureBox1->TabStop = false;
I tried removing the images and it ran but I tried to add them back and it produced the same problem.
Through using the header file .h of the form, I deleted the image selected "BackgroundImage" from the properties side panel.
UI Windows forms was used to develop the GUI by "By ADD New Item" under project bar of visual studio.
Any reasons why?
2
Answers
The most common reason for this is that you have changed the namespace name after a Resourse file has been created.
Eg.
Project1 -> Project12
Solution:
Open vcxproj file -> Find the resx file place: Add tag
<LogicalName>NewNamespace.YourClass.resources</LogicalName>
.Such as :
<LogicalName>Project12.MyForm.resources</LogicalName>
Try to do the following in your "imageBox" Code:
Just go to your Project Main Path in the Windows Explorer and paste your images there.
In our case its "your_image.png".
AND: You have to delete this:
If you leave it in your "imageBox" Code it will always throws the error.
But be aware: you have to put the images under the same name into the compiled folder if you have compiled it.