Bug in Windows Forms?

G

Guest

Dear list,

Anyone else had this - when you delete a resource (such as an image) from
the project it can cause you menu to disappear when you run the application?
Has happened to me a couple of times now. Its taken a few times to work out
why it was happening.

David
 
S

Stoitcho Goutsev \(100\)

David,

I don't quite uderstand. Are you talking about VS designer and VS menus or
your are addressing some problem that happens with the menu of your
application at run time?
 
G

Guest

Stoitcho Goutsev (100) said:
David,

I don't quite uderstand. Are you talking about VS designer and VS menus or
your are addressing some problem that happens with the menu of your
application at run time?

Hi Stoitcho,

This problem arises when I'm building a Windows Forms application in the
VS2005 Designer. The menu is present on the designer view along with the menu
items, but when the application is launched the menu is either missing
altogether or the menu items are missing.

This has happened a couple of times now and it seems to correspond (perhaps)
to when you delete resources from the project such as image resources. It
also happened 'near the time' when I disabled the maximise button on the Form
properties window, so it might be something to do with that. Not sure exactly
what caused this starnage behaviour to occur. I will try and remember the
exact steps I took if it occurs again.

David
 
G

Guest

Hi,

Just quickly tried this again.

I created a Windows Form app (C#)
I added a menu strip and place a couple of menu items in the strip (File,
View...)
I added a PictureBox to the form.
With the picturebox selected I selected its 'Image' Property.
I imported a bitmap resource and it was placed in the picturebox.
I imported another bitmap resource and assigned it to the picture box.
I deleted the first resource.
The compiler complained saying it couldnt find the resource I deleted so I
removed the code where the deleted resource had been declared.
I rebuild with no errors
I launch the Windows Forms application and the menu items are missing, even
though they are still present in the designer.

I'm not sure, is this a 'feature', or a bug?

David
 
M

Markus

I'm not sure, is this a 'feature', or a bug?

I don't know, as I am not using Visual Studio - but it is at least not a
bug of Windows Forms. Rather of Visual Studio or it's designer. So just
a bug in a program and not in some library...

Sorry to make this clear, but people always seem to mix up Visual Studio
and the .NET Framework / Class Library.

Markus
 
S

Stoitcho Goutsev \(100\)

David,

I cannot reporduce the problem. I repeat the steps, but my meny strip is
still there.

How do you delete the resource. You delete the file only or you delete the
resource from the Resources.resx file?

Is there any other controls on the form?

Markus, I agree and disgree with your. I agree that some times people cannot
draw the line between the .NET framework and VS. At the same time I disagree
because there are places where windows forms controls for examples, which
are part of the framework, contain code that is used only to support the
design time. Idealy the design time code is isolated in a separate dll, but
in practice this is not always posible. This design time feature may not
only be used in VS. Any application can host a designer - example is
SharpDevelop IDE. If there is a bug in this code it will show up in VS at
design time, but I'd consider this as a bug in the framework.

Good example is the PropertyGrid. Some people may think of it as part of the
VS, but it is actually Windows forms control and can be used anywhere. I
dare to say that this control has quite few bugs in it. I also dare to say
that one will find more bugs in his/her application when using it than in
VS. So, this is an example where one can say - 'This is VS bug' where
actually this is a .NET bug.
 
M

Markus

At the same time I disagree
because there are places where windows forms controls for examples, which
are part of the framework, contain code that is used only to support the
design time. Idealy the design time code is isolated in a separate dll, but
in practice this is not always posible. This design time feature may not
only be used in VS. Any application can host a designer - example is
SharpDevelop IDE. If there is a bug in this code it will show up in VS at
design time, but I'd consider this as a bug in the framework.

Ok, here I fully agree with you. But such bugs are not often discussed
(if you would make statistics over all the questions here in the
newsgroup and compare them with talks like "I use VS.NET" - "OK fine,
which version of the .NET Framework" - "2003").

Maybe it's Microsoft's fault, who give away the IDE and build in
anything into it. I would prefer a more divided way, a IDE and the
Framework. Then ridiculous things as the need of 2 IDEs for 2 different
..NET Framework version would stop... that's just one of the main reasons
for me NOT to use VS.NET.


.... before getting too philosophical...

bye
Markus
 
G

Guest

David,
I cannot reporduce the problem. I repeat the steps, but my meny strip is
still there.

How do you delete the resource. You delete the file only or you delete the
resource from the Resources.resx file?

Is there any other controls on the form?

Hi Stoitcho,

When I add the image file I do so via the Image Property of the PictureBox
i.e. I import it there. There is no Resources.resx file added, the designer
creates a Folder called Resources visible in my solution explorer. When I no
longer need the image I delete it from that folder - the Resources folder.
There is no other controls on the form.

HTH
David
 
S

Stoitcho Goutsev \(100\)

David,


When you import an image using the Images property editor VS gives you two
choices - to import as local resource or to import as project resource; the
latter is by default. (I assume we are talking VS2005 here because you
mentioned menu strips)



When you import as local resource no image file is added to the project and
the image goes in the form's resx. You can see that files when you expand
the form's node on the solution explorer. When you open the form's resx in
order to see the images you need to switch the view from the designer
toolbar.



When you import as project resource VS copies the image and adds a link to
it to the project's resources.resx file. This file is located under the
Properties node in the solution explorer. If you delete the image file it is
still referenced there that's why you get that error message that you
mentioned. You need to delete it from that resx file also.



Anyways, I still cannot repro the problem. There might be something else in
your application. Can you reproduce it in a clear test application with one
menu and one picture box only?
 
G

Guest

Hi Stoitcho,

When I import an image it was using the default method i..e import as
project resource; So perhaps it does in fact create the .resx file which I
made a mistake before by saying it didnt. I tried again with a clean test
app. here is the steps I took -

Create new Windows Forms application in C#

Add a menu strip and add a couple of items ie. File, edit...

Add a Picture Box

Click on PictureBox and select Image Property

Import an Image (select the default way to do it i.e. create a .resx file)

Build and launch app...all is well, menu displayes, image displays too...

Close form, go back to designer...

Click on PictureBox and import a different image (same way as before)

Build and launch app, all is well, menu shows, new image shows.... close
app..back to designer...

Now delete the first image you added..build and run...you get an error,
delete the bit of code giving the error..

Now import a new image into PictureBox...build and run...menu is missing
items.

HTH
 
S

Stoitcho Goutsev \(100\)

David,

Sorry, but I cannot repro the problem. Can you try on a different machine it
might be something wrong with your VS.
 
S

Stoitcho Goutsev \(100\)

David,

Actually I think I managed to repro the problem.
What I can only suggest is to delete the image first from the Resources.resx
and then from the folder.
Importing the image as project resource affects the project in several
places:
1. It adds the image file
2. It adds entry to the Resources.resx file
3. It adds a property to the <namespace>.Properties.Resources class
4. It adds code to the form's InitializeComponent.

It look like VS cannot keep those places in sync very well if it is not done
in the expected way.

If you do it in the following way I believe you won't have a problem.

1. Open the form in the designer and reset the Image property. This will
remove the code from the InitializeComponent method.
2. Double click on the Resource.resx file in the Solution Exporer and delete
the image resource from the designer. This will take care of the resx xml
file and Properties.Resources class
3. Delete the image from the project.
 
G

Guest

Hi Stoitcho,

Sorry for the late reply! Pleased you manage to reproduce the problem. I'll
bear in mind your workaround next time I have to delete images.

Cheers!
David
 

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