seun
seun

Reputation: 41

Controls on Form Not Shown in Designer

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?

Upvotes: 4

Views: 12280

Answers (6)

Robert Johnson
Robert Johnson

Reputation: 11

Adding this answer because I don't see it here already.

If, in the constructor for the custom control, you are doing things like getting data to populate the control with, that can cause the problem of the control not being displayed in the designer.

To test for the above, just comment out any code you have in the constructor for the control other than InitializeComponent() and then rebuild the solution and check whether the control is showing up in the designer.

If this fixes your problem then move the code that you commented out in the constructor of the control into the constructor of the form, adjusting scope of methods and sub-controls as necessary to make them accessible from the form.

I don't really know why the above solution works, but I think it has to do with the order in which the code executes. I think that trying to populate the control with content before the form has initialized itself is the problem.

Upvotes: 1

formUser1
formUser1

Reputation: 21

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.

Upvotes: 2

TheFullmetal
TheFullmetal

Reputation: 11

  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

Upvotes: 1

somaye boroumand
somaye boroumand

Reputation: 1

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

Upvotes: 0

ako
ako

Reputation: 179

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....

Upvotes: 2

jrob
jrob

Reputation: 532

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.

Upvotes: 0

Related Questions