Doug DeBug

I'm not sure how--but I've managed to add some controls such as buttons, combo boxes, and others to my project in VB Express that are not visible. I don't mean hidden like control.hidden = true but hidden on the form. I think they are hidden behind 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



Re: Windows Forms Designer Windows Form Designer and the 'Do not modify... warning

EvilPenguin

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




Re: Windows Forms Designer Windows Form Designer and the 'Do not modify... warning

Doug DeBug

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 remove the control and the code in 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 hacking that code with a dull kitchen knife by a novice coder Do I even dare





Re: Windows Forms Designer Windows Form Designer and the 'Do not modify... warning

EvilPenguin

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




Re: Windows Forms Designer Windows Form Designer and the 'Do not modify... warning

Doug DeBug

EvilP,

I was able to verify that all the controls that I could see by tabbing through all the controls were in fact re-named by what they do like 'btnSearch' and that the rouge controls were still named as 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 the event 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 later renaming the button1 to btnSearch. To fix that, I simply copied the meat of the code to the clipboard, deleted everything from the sub to the end sub, selected the event from the drop down to insert the code stub, and then finally pasted the clipboard code back in the event procedure.

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.

Thanks for you help on this question!

DeBug





Re: Windows Forms Designer Windows Form Designer and the 'Do not modify... warning

KClawson

 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.





Re: Windows Forms Designer Windows Form Designer and the 'Do not modify... warning

Doug DeBug

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