Jul 14, 2008

View Designer went MIA in Visual Studio 2008

Today I went to make some changes to a form in an application. I haven't worked on this form in a couple of weeks and when I went to visually edit the form I couldn't. When I right clicked there was also no option for "View Designer". The form designer in Visual Studio 2008 for this form was gone, missing, AWOL, kaput. Luckily the form designer was still available for all the other forms in my system. When I compiled and ran the form was still there and worked correctly (whew). I just couldn't do any visual editing on it. The form in question was MainForm.cs and as you can see in the photo to the left the Icon for the form is missing. I delved into the .csproj file and sure enough the tag had been changed to code instead of form. I changed it back but it didn't do any good. Visual Studio corrected it for me and made it code again. I then tried various things, repeated steps, pulled out some hair, watched some of the remaining hair turn grayer and then tried to force the issue with Attributes. I added the following attribute above the MainForm class [System.ComponentModel.DesignerCategory("Form")] This didn't work but it did cause a compiler error stating that the form was already expliclity designated as code. Sure enough a different file containing a partial class had the same attribute only with "Code" instead of "Form". I deleted that attribute, exited and restarted and everything returned to normal. I have no idea how the other partial class got attributed that way and I would have sworn that today is the first time I ever even saw this attribute. Maybe I went into a trance, channeled this attribute and typed it into the file. A speaking in tongues kind of experience for a computer geek. That or more likely it was just gremlins hard at work. At any rate if it happens to you, check your attributes.


Anonymous said...

I had this problem with VB 2008 Express. The FormMain.vb file somehow became empty and I added to it:

Public Class FormMain

End Class

I had not yet done anything with the form except to add a button to call another form and an Exit button. Weird.

Anonymous said...

I had a very similar problem wherein my forms and controls ALL lost the designer option, the icon showing them as form or control, and double clicking on them still did not bring up the designed.

What I did was I went into the 'designer' generated code, at the top, and wherever there was 'Inherits System.Windows.Forms.Form' I changed it to UserControl and back (and vice versa), and as though by magic(!) VS2008 realised they were designed controls, and the problem was solved.

Anonymous said...

I had this problem and thought it might be something to do with DevExpress components. However, I tried the suggestion from the earlier anonymous poster about adding:
Public Class formname
End Class
It worked a treat and I am extremely grateful to you for the solution!

Anonymous said...

With DevExpress Form v10.1, I also lost designer. In *.Designer.vb (at top of partial class), I changed
Inherits DevExpress.XtraEditors.XtraForm
Inherits System.Windows.Forms.Form,
cleaned and rebuilt the project...closed and reopened, and got the designer back. I then fixed my inherit line back to devexpress code and repeated the steps.
This process resolved the issue.

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.