problem with pictuerbox

M

ma

Hello,

I am new in .NET and I am writing my first program in c++/CLI on MSVC
2005.



I add a PictureBox to my form and then using its properties I change its
image property to one image from my hard disk. it generate the following
code for me:

this->image1->Image = (cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"image1.Image")));

but when I am running my program, it generate an exception with the error
that it couldn't find the specified objects in my resources. I checked the
resource and there is no resource with this name there.

What is wrong with this?



Best regards
 
B

Bruno van Dooren

but when I am running my program, it generate an exception with the error
that it couldn't find the specified objects in my resources. I checked
the
resource and there is no resource with this name there.

What is wrong with this?

As I mentioned in vc.language, It should work, so you have to find out why
it doesn't get added.
Have you tried to add image1 manually?

double click the resource, select 'images' in the top left of the resource
window.
that way you see what images exist.
In the resource window, Select Add resource->New image then select the
correct extension and add your image manually.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
M

ma

Thanks for your suggestion.
I did some more work and I found that the resouirce is actually there but
when I try to read it i am getting the following error:
An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

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

what is culture?

best regards
 
G

Guest

Thanks for your suggestion.
I did some more work and I found that the resouirce is actually there but
when I try to read it i am getting the following error:
An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

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

what is culture?

If you want users from different countries to be able to use your
application in their native language, you can use localization.

if you look at the propery page of your windows form, there is a property
called language. if you select a language there, every make-up action you
perform on the form will be tied to that language.

For example, in your case this would mean that you would have 2 pictures for
2 languages. the language is determine by the localization settings in the
windows control panel.

If the program runs on a computer for which there is no specific resource,
the program will try to load the language 'neutral' resource.

I suggest you do the following: In your resource file (if you right click it
in the solution explorer ->view code) you can see the language for which the
picture was added. In my project this is neutral (the default setting).
My guess is that whatever you find there is not neutral, and different from
the locale of your machine.

When you start your app, the program will try to load the resource for the
locale of your machine, does not find it, tries to load the neutral resource,
cannot find it and finally throws an exception.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
M

ma

Thanks for your good explanation.



I check and found that the language of my form is default and in the
resource the culture is neutral

See the extract from my form resource:



assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing"
mimetype="application/x-microsoft.net.object.bytearray.base64">

<value>

What should I do now?

Best regards
 
G

Guest

ma said:
Thanks for your good explanation.



I check and found that the language of my form is default and in the
resource the culture is neutral

See the extract from my form resource:



assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing"
mimetype="application/x-microsoft.net.object.bytearray.base64">

<value>

What should I do now?

Best regards

This should be OK.
Btw I just realized that your form has localization disabled .otherwise you
won't get the explicit initialization of the picturebox directly in your code.

However, your code contains this:
resources->GetObject(L"image1.Image")));
but your resource file contains this:
<data name="pictureBox1.Image"

the names don't match. there is no image1.image in your resource file.
try to change the name of the resource that initializecomponent tries to
load to the name that is in your resource file. they should be the same.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top