Francesco Bonizzi
Francesco Bonizzi

Reputation: 5302

Errors with Microsoft "WinForms Series 1: Graphics Device"

I have a problem with this sample. I just downloaded it and run it (Visual Studio 2010). I haven't touched anything.enter image description here

Sorry for the Language, it is in italian. From top to bottom it says:

Note that:

I really don't understand what's happening.

Edit By JT: The repro is here: sdrv.ms/1kIhI5o

Repro steps:

Open solution
Select the flowLayoutPanel1 control
Run the application
Stop the application
Now try to select the gameWrapper!

Result:
The gameWrapper control cannot be selected anymore, it doesn't even show up in the Property Windows dropdownlist of form controls!

Upvotes: 8

Views: 540

Answers (7)

Jeremy Thompson
Jeremy Thompson

Reputation: 65554

I added repro steps into your question and experienced half of the problem.

Repro steps:
1. Opened solution
2. Selected the flowLayoutPanel1 control
3. Ran the application
4. Stopped the application

Then I could not select the gameWrapper control! The gameWrapper control didn't even show up in the Property Window's dropdownlist of form controls!

I tried adding controls as you mentioned to cause the problem, I even added the SpinningTriangleControl.cs user control that is showing in your screenshot as the problem (but it wasn't included in the repro solution thats been uploaded).

To reproduce the SpinningTriangleControl.cs user control unable to be opened as per your screenshot, you just leave out the using OhmGame_Level_editor; Namespace reference:

enter image description here

enter image description here

Adding the using OhmGame_Level_editor; allowed me to open the SpinningTriangleControl.cs user control without the designer error.

It must be a XNA/Visual Studio bug - how when a control besides the gameWrapper is selected and then after running/stopping the application the gameWrapper control is visible but cannot be selected!

Workaround:
I found when I opened solution and locked the gameWrapper control then I could select it no matter if it was or wasn't selected when running/stopping the application.

enter image description here

Upvotes: 1

Scope Creep
Scope Creep

Reputation: 565

I have seen this occur in a few scenarios.

1) Project gets a reference to itself.

If you have a usercontrol in project A, and use the design to add the usercontrol to a form also in project A, Visual Studio will add a self reference which will screw up the designer.

2) Making an abstract base class for a visual element.

Since abstract classes can't be instantiated, the designer will not be able to create an instance to render in the designer.

3) DesignMode bug

If you are using the DesignMode property to determine whether or not UserControls should load data in an event like Load(), you need to know that DesignMode will break if you nest controls more than one level deep. You can get around this by creating your own designmode variable by keying off of LicenseManager.UsageMode.

Upvotes: 1

Guillaume Michel
Guillaume Michel

Reputation: 1204

I had a problem in the designer with form that inherits from other forms. The designer simply doesn't want to display them. In my case, the designer was lost because there was no constructor with no argument. The code compiled and executed well because I used the constructor with 1 argument. To tidy up a bit the code, I tried to delete the constructor with no argument, but I had to put it back to make the designer work. You may try to set a constructor with no argument in both the inherited and base control.

Upvotes: 0

Ringo
Ringo

Reputation: 3965

You should try to Throw in some try/catches and use breakpoints and finding the exception with it. Also I think your problem refer to something with GUI component like SpriteFont, ContentManager, GraphicsDevice...For example:

content = new ContentManager(Services, "Content"); 

spriteBatch = new SpriteBatch(GraphicsDevice); 

font = content.Load<SpriteFont>("fontName"); // make sure font was loaded fine.

Upvotes: 0

Radin Gospodinov
Radin Gospodinov

Reputation: 2323

This seems to caused by wrong reference. Try the following: Close all files. Clean the solution and rebuild. Then locate the project or dll where GraphicsDeviceControl class is defined. Delete the reference. Re-add the reference, rebuild. Try to open the control again.

Upvotes: 0

sunnytyra
sunnytyra

Reputation: 89

Generally such problem is seen while creating a custom control. For this Build the WinFormsGraphicsDevice and paste the generated exe to the following path of the version of Visual studio you are using.

C:\Program Files\Microsoft Visual Studio \Common7\IDE

restart your visual studio and see if this problem is solved. I faced problem with my custom controls and fixed it this way. Hope it works for you too.

Upvotes: 0

Mariano
Mariano

Reputation: 1073

This happens to me as well from time to time. The only thing that works is deleting the custom control from the window and then adding it again.

Upvotes: 1

Related Questions