4

I am working on a WinForms project, and I have a form where I have a DataGrid, a TextBox, and 2 button controls (btnNew and btnSearch). The click event of a btnSearch is supposed to perform a search on the DataGrid.

I deleted the event handler for the search button and have saved my work. It now appears that all other controls have been deleted and the form is back to the default state. The application works fine though when run, with some errors. I have resolved the error but the designer view is still in the default state. How do I go about reinstating my form's design view?

Unihedron
  • 10,902
  • 13
  • 62
  • 72
seun
  • 41
  • 1
  • 1
  • 2

5 Answers5

2

i had your problem and solved it in this way:

just make another form with another name(NewForm.cs) and copy the InitializeComponent() content from YourFirstForm.designer.cs and paste it into NewForm.designer.cs InitializeComponent() function. but be careful when copy and paste the function content change all YourFirstForm keywords to NewForm . finally Remove YourFirstForm and just work with your NewForm....

ako
  • 179
  • 7
2

With the control selected in the properties window.

  1. Right click on an empty space on the form,
  2. Click cut
  3. Right click / then paste into a cell somewhere in a form control.
formUser1
  • 21
  • 1
1
  1. Make sure all errors related to form are removed and your code compiles successfully.
  2. If Form has been copied from an existing project make sure Form.Designer.cs and Form.resx are under same parent Form.cs and not separate. Check Form tree in Solution explorer. If they are not under the same tee, load the designer.cs and .resx file again in the project.

Form.resx and form.designer.cs under same tree as form.cs

kalehmann
  • 4,821
  • 6
  • 26
  • 36
  • This was my problem. Thanx alot boss. Anyway I could not load it again from the copied project. Even if I add again it did not list under the same parent. So what I did was I created a new form with the same name and then replaced the files with previous files. Then it listed under same parent. now it works. Thanks again – nuwancy Aug 21 '23 at 17:09
0

I've run into errors like this before where simply closing all the form's files (code view + design view) re-open the code view and then Shift-F7 to reload the design view would fix it.

If that doesn't work perhaps fixing the error you mentioned in the designer view caused something to get out of whack. Try comparing the structure in the YourForm.Designer.cs file with a new form to see if an inadvertent edit was made.

jrob
  • 532
  • 1
  • 6
  • 16
0

i had your problem in Visual Studio 2017 and solved it in this way: -select controls by Properties -view Location is - -change the Location -drag the control to another location