Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
2.80/5 (3 votes)
I have a project in Visual Studio 2012. This is a windows forms project. Suddenly the form doesn't show any controls when I view it in design view. But when I run the program, I do see the form and all the controls. Why is this happening? Please note that this project was made in the same Visual studio 2012. How can I overcome this? Please advice.
Posted

1 solution

You did not show any code, so no one can point out where the bug is. However, I can give you the advice on what you do.

The situation is pretty typical: some piece of your code can throw an exception when it is executed by a designer, by one or another reason. You can use one simple technique for two purposes at the same time: 1) to pin-point the problem, 2) to avoid it. Look at the property System.Windows.Forms.Control.DesignMode:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control%28v=vs.110%29.aspx[^].

Start putting the pieces of your code under the "if" block, such as
C#
if (!myControl.DesingMode)
{
   // your existing code
}

// ...

if (!myForm.DesingMode)
{
   // your existing code
}

// ...

As adding this check does not modify the behavior during the execution of your application, it won't be broken. At the same time, some code which causes the problem under the designed will be eliminated from the execution. This is just the idea, but it works very effectively in such cases.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900