Windows Develop Bookmark and Share   
 index > Windows Forms Designer > VS 2008 SP1 abstract Form/UserControl not working even when using Brian Pepin, Urban Potato, technique. Help...
 

VS 2008 SP1 abstract Form/UserControl not working even when using Brian Pepin, Urban Potato, technique. Help...

Hello everyone,

I'm using Visual Studio 2008 SP1 and I'm following this article:

http://www.urbanpotato.net/default.aspx/document/2001

So I created a new WindowsFormsApplication project. I added this code to the Form1.cs file

1 namespaceWindowsFormsApplication70
2 {
3 [TypeDescriptionProvider(typeof(ConcreteClassProvider))]
4 publicabstractpartialclassForm1:Form
5 {
6 publicForm1()
7 {
8 InitializeComponent();
9 }
10
11 publicabstractstringAbstractProperty{get;set;}
12 }
13
14 //HereisaconcreteversionofAbstractFormthatactsasastandin
15 internalclassConcreteForm:Form1
16 {
17 string_abstractProperty;
18
19 publicoverridestringAbstractProperty
20 {
21 get{return_abstractProperty;}
22 set{_abstractProperty=value;}
23 }
24 }
25
26 //Hereisourtypedescriptionprovider.Allourproviderneedsto
27 //doisreturnConcreteFormasthereflectiontype.
28 internalclassConcreteClassProvider:TypeDescriptionProvider
29 {
30
31 //BecauseweonlywanttoaugmentthemetadataforAbstractForm,insteadof
32 //completelyreplaceit,wepassintothebaseclassthecurrenttype
33 //descriptionprovider.Thisistheproviderthatnormallyhandles
34 //metadataforAbstractForm.Bydoingthisallwehavetodois
35 //overridetheareaswewanttochange.
36 publicConcreteClassProvider():base(TypeDescriptor.GetProvider(typeof(Form1))){}
37
38 //Tellanyonewhoreflectsonusthattheconcreteformisthe
39 //formtoreflectagainst,nottheabstractform.Thisway,the
40 //designerdoesnotseeanabstractclass.
41 publicoverrideTypeGetReflectionType(TypeobjectType,objectinstance)
42 {
43 if(objectType==typeof(Form1))
44 {
45 returntypeof(ConcreteForm);
46 }
47
48 returnbase.GetReflectionType(objectType,instance);
49 }
50
51
52 //IfthedesignertriestocreateaninstanceofAbstractForm,weoverride
53 //itheretocreateaconcereteforminstead.
54 publicoverrideobjectCreateInstance(IServiceProviderprovider,TypeobjectType,Type[]argTypes,object[]args)
55 {
56 if(objectType==typeof(Form1))
57 {
58 objectType=typeof(ConcreteForm);
59 }
60
61 returnbase.CreateInstance(provider,objectType,argTypes,args);
62 }
63 }
64 }

I build the solution and everything works fine. Then I added another Form called Form2 and this is what I have on that Form2.cs file:

1 namespaceWindowsFormsApplication70
2 {
3 publicpartialclassForm2:Form1
4 {
5 privatestring_AbstractProperty;
6
7 publicForm2()
8 {
9 InitializeComponent();
10 }
11
12 publicoverridestringAbstractProperty
13 {
14 get
15 {
16 returnthis._AbstractProperty;
17 }
18 set
19 {
20 this._AbstractProperty=value;
21 }
22 }
23 }
24 }

All pretty basic as you can see.... When I try to open Form2 in the Designer I get the usual error:

The designer must create an instance of type 'WindowsFormsApplication70.Form1' but it cannot because the type is declared as abstract.

Any ideas why is the designer still giving me this error? Did I miss something?

Thanks a lot in advance
Federico Silberberg  Thursday, February 19, 2009 5:30 PM

Hi Federico Silberberg,

I have copied all your code to build my project. Yes, the error shown when I try to open the designer of Form2. Then I copy all the code of Form1 to the same file as Form2, I can successfully open the Form2. I don't know the exact reason.

The step is:
1. Delete Form1
2. Copy all code to Form2, that mean in Form2.cs, there are two class.
3. Rebuild the project. Close all form and close the designer.
4. Reopen the solution, double click Form2, you can see it shown in the designer.

Does this step help you?
Don't hesitate to tell me if you have any question.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, February 23, 2009 7:11 AM

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post editor window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, February 26, 2009 10:01 AM

You can use google to search for other answers

Custom Search

More Threads

• PictureBox transparency.
• Designer Serialization (SplitContainer, third parties etc.)
• Own combobox problem with focus
• Lost my main form in designer
• How can I save or change application settings?
• Custom glyph/behaviour problem
• Why does my run-time form not look like my design-time form?
• Client Area
• what does the signal ">" in the css selector "#aaa > .bbb" mean?
• Visual Studio 2008: Error analysis EntityName