Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Windows Form Designer and the 'Do not modify... warning
 

Windows Form Designer and the 'Do not modify... warning

I'm not sure how--but I've managed to add somecontrols such as buttons, combo boxes, andothers to my project in VB Express that are not visible. I don't mean hiddenlike control.hidden = true but hidden on the form. I think they are hiddenbehind other controls that I have on my form. I can see the drop down events of these hidden controls which have no code associated with them. When I view the code in the partial class generated by the Windows Forms Designer I can see the referece to them like:

Me.MaskedTextBox2 = New System.Windows.Forms.MaskedTextBox

Me.ListBox1 = New System.Windows.Forms.ListBox

Me.MaskedTextBox1 = New System.Windows.Forms.MaskedTextBox

Me.ComboBox2 = New System.Windows.Forms.ComboBox

Me.Button1 = New System.Windows.Forms.Button

The warning:

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

I think I need to delete them through the form design tool but if I can't see them how do I select them and then simple press the delete key? All my valid controls have descriptive names like btnSearch and tbUser so I feel safe in deleting anything with the default name followed by a number. Well kinda safe....

DeBug

Doug DeBug  Sunday, February 11, 2007 6:19 PM
Just make suer that you don't close the code window after your edits. Try to open the design view of the form, and then run the program to see if your changes have had any other effects.

If something doesn't work properly, then just switch back to the code view, and hold Ctrl-Z until things work again :)

If you want an easier way to track down the lines to change, just remove the declaration line, and then use the error window (double-click on the errors) to find the other lines that you have to remove.

If you want to be really safe, just take an full backup of your project directory before you start.

HTH
EvilPenguin  Monday, February 12, 2007 3:57 AM

 Doug DeBug wrote:

Just for fun, I would still like to know how to select a control that is hidden behind another container control so I can delete it by simply pressing the DEL key.  Until then, editing the 'do not edit' partial class file will work.

I know three off the top of my head:

1) If you're using Visual Studio 2005, then right-click on the container control - part of the popup menu is a list of all the controls underneath the mouse pointer, even if they aren't on top. 2003 doesn't have this I don't think.

2) Another way is to select the control from the Properties window drop-down. Hit F4 to bring up the properties window, and at the top of it is a drop down that lists every item on the form. Selecting a control in that drop down also selects it on the form. The key at this point is to bring the focus back to the designer without clicking on another control. I find clicking on the tab at the top of the designer surface (the part that has the form name) does the trick.

3) There's also the Document Outline window (View Menu/Other Windows/Document Outline), which shows you all the controls on the form in a hierarchical view based on where they are parented. Selecting a control in this window also selects it on the form.

KClawson  Friday, February 16, 2007 9:18 PM
You have two options... If you can select them using the combo box at the top of the properties window, you should just be able to press delete.

If that doesn't work, then you can modify the 'Do not modify' code.
Just remove any line with a reference to the control you want to remove. There should be:
  • A declaration line (System.Windows.Forms.MyControl myControl1)
  • An initialization line (myControl1 = new System.WindowsForms.MyControl())
  • A number of lines grouped together setting properties on the new control
This last line should be underneath a comment with the name of the control. In c# it looks like this:

//
// myControl1
//
[set properties]


Hope this helps
EvilPenguin  Sunday, February 11, 2007 10:18 PM

Option 1: I tried to select the hidden control by selecting it from the drop down box at the top of the properties window. However, pressing delete did not delete the control. If I select a visible control with the mouse it selects it with the move handles and pressing the delete key will removethe control andthe codein the Windows partial class. I can select all visible and hidden controls by pressing "CTL A" and I can also select all the controls with the TAB order tool. I was hoping to only select the hidden control without the need to click it with the mouse.

Option 2: I guess it's OK to edit the "Do not edit" code but I tried that once on another project and the form refused to load after that. I know that the Windows forms designer is simply coding what could be coded by hand but hackingthat code with a dull kitchen knife by a novice coder?Do I even dare?

Doug DeBug  Monday, February 12, 2007 1:42 AM
Just make suer that you don't close the code window after your edits. Try to open the design view of the form, and then run the program to see if your changes have had any other effects.

If something doesn't work properly, then just switch back to the code view, and hold Ctrl-Z until things work again :)

If you want an easier way to track down the lines to change, just remove the declaration line, and then use the error window (double-click on the errors) to find the other lines that you have to remove.

If you want to be really safe, just take an full backup of your project directory before you start.

HTH
EvilPenguin  Monday, February 12, 2007 3:57 AM

EvilP,

I was able to verify that all the controls that I could see by tabbing through all the controlswere in fact re-named by what they do like 'btnSearch'and that therouge controls were still namedas the default control1, control2, etc. I zipped the entire directory for backup each time I was able to create a working build.I edited the'Do not edit'partial class until all that remained were the named controls. Done.

After that, some of theevent code behind the buttons and combo boxes stopped working.I saw that some of the event handlers like 'handles btnSearch.click'that are placed after the parameters were missing. I think that was related to adding an event to button1 and then laterrenaming the button1 to btnSearch.To fix that, I simply copied the meat of the code to the clipboard, deletedeverything from the sub tothe end sub,selected the event from the drop down to insert thecode stub, and then finally pasted theclipboard code back in the event procedure.

Just for fun, I would stilllike to know how to select acontrol that is hidden behindanother container control so I can delete it by simply pressing the DEL key. Until then, editing the 'do not edit' partial class file will work.

Thanks for you help on this question!

DeBug

Doug DeBug  Monday, February 12, 2007 2:37 PM

 Doug DeBug wrote:

Just for fun, I would still like to know how to select a control that is hidden behind another container control so I can delete it by simply pressing the DEL key.  Until then, editing the 'do not edit' partial class file will work.

I know three off the top of my head:

1) If you're using Visual Studio 2005, then right-click on the container control - part of the popup menu is a list of all the controls underneath the mouse pointer, even if they aren't on top. 2003 doesn't have this I don't think.

2) Another way is to select the control from the Properties window drop-down. Hit F4 to bring up the properties window, and at the top of it is a drop down that lists every item on the form. Selecting a control in that drop down also selects it on the form. The key at this point is to bring the focus back to the designer without clicking on another control. I find clicking on the tab at the top of the designer surface (the part that has the form name) does the trick.

3) There's also the Document Outline window (View Menu/Other Windows/Document Outline), which shows you all the controls on the form in a hierarchical view based on where they are parented. Selecting a control in this window also selects it on the form.

KClawson  Friday, February 16, 2007 9:18 PM

Thanks! I did not know of the Document Outline window and I've been grinding out code for some time now using the new VS 2005. I had played around with selecting the control from the drop down but never tried to bring the focus back to the designer without selecting another control. I could not get your solution 1 to work when I added a button to a form, covered it with a TableLayoutPanel, and right clicked over where the button was hidden. The only item it would allow me to select was the form itself. No matter, the second and third solution works like a champ!

Thanks again!

DeBug

Doug DeBug  Monday, February 19, 2007 6:06 PM
I'm so glad I found this thread!

I'm just about to do the same thing, removing code in the Form1.Designer.vb, as I have found no other way to delete the controls. The controls I want to remove can be found in the Designer code and in the Properties window but I cannot see them in the design view of the Form, and they are not in the Document Outline. If they would have been found in the Document outline it would of course had been easy. Playing around with "Send to Back" of the visible controls in the design view or tabbing around the controls in the form do not help either as the controls partly have disappeared.

The history behind my hidden controls is that I in the design view moved panels from one Form to another. Obviously they wasn't really moved, but copied, because the controls that are now hidden are the old ones with descrpitive text, but the new ones have the standard names, like TextBox4. There must have been a better way to do this moving, maybe through the Document Outline, that I was not aware of at that time. After removing the old, sort of disappeared controls, I'll have to rename the new controls such that they get the old descriptive names that are used in my code.

Moving and removing things is clearly a tricky and risky buissness for a Visual Studio / VB newbe like me. I've also found that it usually causes the handles to be removed from various sub events, such that they are not invoked anymore.

/Nile
The Nile  Thursday, August 13, 2009 9:22 AM

You can use google to search for other answers

Custom Search

More Threads

• dynamic checkboxes.
• Bug - Getting the SelectedItem in ListBox
• How to display SmartTags/DesignerVerbs in a home made DesignerHost
• how to create AVI from a bunch of Bitmap files in C#
• Designer Save Bug
• Form Designer Questions
• User control
• MSN Messenger type toast, or alert
• SplitterPanel delete - or how can I disable the delete command for a specific component
• In VS2008 the designer loses panels order when inheriting from a UserControl