none
Windows Form automatically convert to Class file RRS feed

  • General discussion

  • I've been trying to make a windows form for the 3rd time now, but everytime i make this form, close the project, and again open it, the form icon converts to the icon of Class file, and I can't view the designer anymore. Even when I right click the form, the "View Designer" option is gone. Now there's only "View Code" and "View Class Diagram" options there. it's weird cuz the other apps i'm making work perfect, but everytime i design this form, this is happening. And I get this error when I reopen the project after closing it once:

     

    The designer could not be shown for this file because none of the classes within it can be designed

    The objects in my form are:

    1 button

    3 labels

    2 timers

    3 oval shapes

    1 rectangular shape

    I'm planning to reinstall my Visual Studio 2010, but I don' think that will help because all other projects are working properly. Only when I create this particular form (tried 3 times), this error occurs. I have a weird feeling that this is happening due to the shapes. Cause when I try to copy-paste the entire form into another form. everything gets copied except the shapes. I can't even copy-paste each shape individually.

    Though, the form still lists the "Form1.Designer.cs" and "Form1.resx" files in the Solution Explorer. But I can't seem to do anything. Is there something wrong with my "Form1.Designer.cs" file or what?


    • Moved by Lie You Friday, April 15, 2011 1:52 AM (From:Visual C# General)
    • Changed type prateek203 Thursday, April 21, 2011 1:13 PM
    Tuesday, April 5, 2011 6:39 AM

All replies

  • If the designer cannot open the Form, it's probably a problem with the InitializeComponent method or with the base class of your form.
    Tuesday, April 5, 2011 4:17 PM
  • If you cannot find the problem, trying adding one piece at a time and seeing where it errors out.  For example, create a blank form, close the project and open it up, is there an error?  Then add a label and repeat.  Repeat this process until it errors the first time and from here you will know which line is causing the issue.  If you have the line that is causing the problem and still cannot figure it out post it here and people will able to help you a little better.  Hope this helps!
    Tuesday, April 5, 2011 4:22 PM
  • Hi,

     

    Welcome the MSDN Forum.

     

    We only copy and paste the entire form UI not include the behind code in designed.cs.

    So if we copy UI which controls are dragged from ToolBox, it should work well. But if we copy UI which controls are dragged and drew by coding, it doesn’t work. So we copy the UI which are mixed with dragged controls and drew controls, we need the code also.

     

    Please have a try to copy the code from the entire form to the other forms.

     


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 6, 2011 7:35 AM
  • Rocky (and the OP),

    The trick has always been to Cut it instead of copying it (and then paste it also back in the original) (after making a save copy or using source safe in Visual Studio Team Server). 

    I'm not sure if that still works in all versions. 


    Success
    Cor
    Wednesday, April 6, 2011 7:49 AM
  • Hi! Thanks!

    It's not that I need to copy-paste. It's just that I am not able to copy the shapes so I think it might be them causing the problem. I'm not copying the designer.cs file anyhow.

    And there's no code in the form. I only dragged-and-dropped the elements from the toolbox. But when I save it and reopen, the windows form is now a class file, which still lists the form1.designer.cs and the form1.resx file.


    facebook.com/prateek203
    Wednesday, April 6, 2011 11:22 AM
  • But it's working fine when I make different projects. lol :P
    facebook.com/prateek203
    Wednesday, April 6, 2011 11:22 AM
  • Yeah I think I might do that. Thanks!

    But for now, I dropped that project, as it was only a test app to get used to c#. Other projects are working fine.


    facebook.com/prateek203
    Wednesday, April 6, 2011 11:24 AM
  • It seems to me that you have written some addittional code on the Default Constructor method of your class ( maybe something to start your timers) or at the Load event.

    To fix it, you just have to add code to run those lines only when the form it's not at DesignMode. Something like this:

    public Form1()
    {
     InitializeComponents();
     if(!DesignMode)
     {
      this.timer1.Enabled = true;
    .
    .
     }
    }

    It won't affect the behavior of your form at runtime, and it will fix the problems you're having at designtime.

    Good Luck


    ...
    Wednesday, April 6, 2011 11:58 AM
  • No, there's no code in the form. I only dragged-and-dropped the elements from the toolbox. Didn't do anything in the constructor or anywhere else.
    facebook.com/prateek203
    Wednesday, April 6, 2011 3:24 PM
  • Hi Prateek,

    I think we should post this issue to the Windows Forms General Forum for more efficient responses.

    Thanks.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 7, 2011 2:03 AM