Hello, I'm having a serious issue with the MenuStrip, and this is happening already for the second time. I was developing my application like I normally do, but a while ago, when I was running the application to preview it (F5/debug), all my menu items were gone. And after that, they were gone in the actual designer view too.
As this is the second time this is happening to my application, I think I may have noticed some kind of pattern, that is related to the resources. I'll try to explain the best I can:
In the Solution Explorer, I have a Resources folder, with some images (icons for the menu, etc), and the last thing I remember having done before the menu items disappeared was only that I moved one of the images to a folder (a folder inside the resources folder, through the Solution Explorer). I then received some notification about the actual resource not being found inside the folder, and I removed the resource (in the resource panel of the 'My Project' properties) and dragged the same image (that I had placed in another folder) again to my project's resources. Then I went to the 'image' property of my picturebox (the one that was using the image that I moved) and I couldn't select any other resource as its image, neither select the 'none' option.
All this may not be quite relevant, or may be confusing, but anyway, I then moved back the image to its initial location, so I would be able to select 'none' as the picturebox's image, BUT after all this confusion with a simple resource image, I then ran my program and suddenly it was like my menu was totally gone. When I came back to the designer view the menuStrip was there, but without any ToolStripMenuItems.
The only strange thing in this is that the code of the menu items is still in the Form.Designer.vb, other than that, it's all normal.
Even if you did not understand something about the 'recreation' of this situation, just focus on the actual issue, that is, I virtually have all my ToolStripMenuItems (even in the object list, in the properties window), but my MenuStrip somehow is not linked to them anymore.
To give you a more concrete example of the situation, take this code for example:
MenuStrip.Items.Add(FileToolStripMenuItem) MenuStrip.Items.Add(EditToolStripMenuItem) MenuStrip.Items.Add(FormatToolStripMenuItem)
If I add this piece of code in the Form_Load() event, all my menu items will reappear, but only at runtime, so you can see that is everything normal except that I just can't see them at design time anymore.
If something is unclear to you let me know. I don't know if this is some kind of bug, but I thought I could have some feedback from you first.
Many thanks, | | F.Costa Thursday, July 13, 2006 8:47 PM | Well thanks for your reply, as it sure gave me a starting point to begin discovering for a solution, but that may not be the case. Anyway, I might have found an apparent working solution, that afterwards was easily discoverable.
In my frmMain.Designer.vb I had this code for the menuStrip:
'
'MenuStrip ' Me.MenuStrip.Location = New System.Drawing.Point(0, 0) Me.MenuStrip.Name = "MenuStrip" Me.MenuStrip.Size = New System.Drawing.Size(512, 24) Me.MenuStrip.TabIndex = 12 Me.MenuStrip.Text = "MenuStrip"
I notice that there was an essential line missing right at the beggining, the one that misteriously disappeared:
Me.MenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem, Me.EditToolStripMenuItem, etc..})
That apparently put all my menu items inside my menuStrip again, in the designer view. Although my problem is resolved, I'm still wondering why would that line have gone away when I was messing with the resources.
I hope this may be useful for someone, or at least give an idea of what to do when such items disappear from the designer view. As you can see it was pretty simple, although I have no idea how did that line deleted itself. So if someone can find a possible logical reason for this to happen I would always appreciate some extra explanation, but in the meantime, I will think of this as a kind of a weird little bug.
Thanks. | | F.Costa Friday, July 14, 2006 1:50 PM | I was facing the same problem. I am in the process of converting vba forms to windows forms. some of my controls are disappearing. Later I found out the location property of missing controls is minus (negative) values. This is some thing to do with the anchor property. if you set the anchor property to none, what will happen is ,if you resize a form/tab/frame. Some of form controls move to new place. so what i did was ,by using the property window, checked the controls locations, if they were negative values, then changed them to known positive values and set the anchor property to top, left. I did this for 20 forms. I hope this will help.
good luck | | vijay1 Friday, July 14, 2006 11:33 AM | Well thanks for your reply, as it sure gave me a starting point to begin discovering for a solution, but that may not be the case. Anyway, I might have found an apparent working solution, that afterwards was easily discoverable.
In my frmMain.Designer.vb I had this code for the menuStrip:
'
'MenuStrip ' Me.MenuStrip.Location = New System.Drawing.Point(0, 0) Me.MenuStrip.Name = "MenuStrip" Me.MenuStrip.Size = New System.Drawing.Size(512, 24) Me.MenuStrip.TabIndex = 12 Me.MenuStrip.Text = "MenuStrip"
I notice that there was an essential line missing right at the beggining, the one that misteriously disappeared:
Me.MenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem, Me.EditToolStripMenuItem, etc..})
That apparently put all my menu items inside my menuStrip again, in the designer view. Although my problem is resolved, I'm still wondering why would that line have gone away when I was messing with the resources.
I hope this may be useful for someone, or at least give an idea of what to do when such items disappear from the designer view. As you can see it was pretty simple, although I have no idea how did that line deleted itself. So if someone can find a possible logical reason for this to happen I would always appreciate some extra explanation, but in the meantime, I will think of this as a kind of a weird little bug.
Thanks. | | F.Costa Friday, July 14, 2006 1:50 PM | I have had a similar problem with VB2005 under Win 2000. When I have deleted a single sub-item from the menustrip VB has crashed. On reopening the project, none of the menustrip items are present. Also you cannot open the code window by double-clicking the menuitem; you have to right-click and select view code. This has repeated several times and now I have lost all my main window menustrip items! I have checked the code for the line you noted was missing, but it seems to be there and correct -
'MenuStrip1
'
Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem, Me.EditToolStripMenuItem, Me.ActionToolStripMenuItem, Me.ConfigToolStripMenuItem})
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
Me.MenuStrip1.Name = "MenuStrip1"
Me.MenuStrip1.Size = New System.Drawing.Size(836, 24)
Me.MenuStrip1.TabIndex = 3
Me.MenuStrip1.Text = "MenuStrip1"
so it looks like a similar but slightly different problem - any thoughts??
Iain M | | Iain Maxted Tuesday, October 17, 2006 7:53 AM | Just found the solution to my problem which may help other people. The following line of code needs to be present in each windows form code page where the menustrip is used. Deleting an item from the menustrip apparently deletes this line of code.
Private Sub ConfigToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigToolStripMenuItem.Click
End Sub
This seems to have cured the problem in all the windows which had lost their menu items.
Iain M | | Iain Maxted Tuesday, October 17, 2006 8:56 AM | Thanks for the additional info. It certainly can help some people thathave multiple forms in their project(which was not my case).
Even so, I'm still not able to understand why does this happen, so I'll just assume it may be some kind of bug that may happen onlyunder specific circumstances (or not),but now that we are moreaware of this, all we can do for now is to be carefuland trynot doing it again by mistake. | | F.Costa Tuesday, October 17, 2006 3:43 PM | This happened to me today.
I 'am using 2005 c#.
I believe this issue has something to do with the resource process. I was adding some icon files and deleting some icon files, then i realized i got some trouble.
I google the problem and i got here.
Yes, the problem is that the vs 2005 deleted the .items.addrange, this happend to my menustrip, my toolbarstrip and my statusstrip.
I mannualy add the lines to fix it.
I will try to repeat this problem later. i think that will be helpful to us to void this.
Hope this will be fixed in sp1.
| | Hongbo Liu Wednesday, October 25, 2006 2:16 AM | Hi, I have had the same problem - in fact I now insist we have a copy of the array of buttons that disappear, so we can paste them back in and get working again. I always happens with us when we delete or remove a resource - like an icon.
Only fix we've found is paste the array back in!!
Be carefull out there !!!
Steve | | Steve Thornton Sunday, November 12, 2006 8:36 PM | Thanks, F.Costa! I was having the same problem, and your solution was extremely helpful. I agree this is a very strange bug. It happened to me after I had to modify the resource.resx file. It wasn't updating when I imported some new resource images, and caused an error because one was deleted but still remained in the file. I modified the resources file to account for these changes, andencountered the exact same problem you did. Your solution worked, but it's still very mysterious why that line would have disappeared. | | tennisnut Sunday, August 17, 2008 5:41 PM | May u Try this if as possible as :
MenuStrip msObj = new MenuStrip();
//For Level1: MainMenu1
ToolStripMenuItem tpMenuItem1 = new ToolStripMenuItem();
tpMenuItem1.Name="MenuItem1";
tpMenuItem1.Text = "MyMenuItem1";
//For Level2: SubMenu1
ToolStripMenuItem tpMenuItem11 = new ToolStripMenuItem();
tpMenuItem11.Name="MenuItem11";
tpMenuItem11.Text = "MyMenuItem11";
//Adding the Level2 of SubMenu Item1 to Level1 of MainMenu
tpMenuItem1.DropDownItems.Add(tpMenuItem11);
//For Level3: SubMenu2
ToolStripMenuItem tpMenuItem12 = new ToolStripMenuItem();
tpMenuItem12.Name="MenuItem12";
tpMenuItem12.Text = "MyMenuItem12";
//Adding the Level2 of SubMenu Item2 to Level1 of MainMenu
tpMenuItem1.DropDownItems.Add(tpMenuItem12);
//For Level1: MainMenu2
ToolStripMenuItem tpMenuItem2 = new ToolStripMenuItem();
tpMenuItem2.Name="MenuItem2";
tpMenuItem2.Text = "MyMenuItem2";
//For Level2: SubMenu1
ToolStripMenuItem tpMenuItem21 = new ToolStripMenuItem();
tpMenuItem21.Name="MenuItem21";
tpMenuItem21.Text = "MyMenuItem21";
//Adding the Level2 of SubMenu Item1 to Level1 of MainMenu
tpMenuItem2.DropDownItems.Add(tpMenuItem21);
msObj.Items.Add(tpMenuItem1);
msObj.Items.Add(tpMenuItem2);
//msObj.Location = new Point(50, 100);
this.Controls.Add(msObj);
Output Will get as :
---------------------------------------------
|tpMenuItem1 | tpMenuItem2 |
---------------------------------------------
| tpMenuItem11 | | tpMenuItem21 |
|--------------| --------------
| tpMenuItem12 |
--------------
| | My Best Solutions Wednesday, September 09, 2009 11:37 AM |
|