Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How does Visual Inheritance work in .Net?
Message
From
20/06/2007 16:58:49
 
 
To
20/06/2007 15:06:02
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01234107
Message ID:
01234592
Views:
16
>Does this work with inheritance, as well? In other words, if you create a base label class with Font = Arial 8pt, then subclass it without touching the Font properties, drop your subclassed labels to a bunch of forms, then decide that Arial 8pt looks hideous and change the base label class' font to Times Roman pt 20 (beautiful!), does the message "change label fonts to Times Roman pt 20) go to all of the projects with all of the forms that use the subclassed labels, so that they, too, will look that much prettier without any additional programmer intervention?

If you do: Label sample = new BigLabel();

of course it works. Now the problem, again is the designer. When you drop the label the first time the stupid thing generates code like:
this.bigLabel1 = new YourLibrary.BigLabel();
this.bigLabel1.AutoSize = true;
this.bigLabel1.Font = new System.Drawing.Font("Verdana", 24F);
this.bigLabel1.Location = new System.Drawing.Point(9, 42);
this.bigLabel1.Name = "bigLabel1";
this.bigLabel1.Size = new System.Drawing.Size(171, 38);
this.bigLabel1.TabIndex = 1;
this.bigLabel1.Text = "bigLabel1";
Of course, this means that when you change your class, your instance GETS the changes, and then is bluntly overridden by the designer code. If you ask me, yes, it is stupid. The usual workaround is the one Kevin explained here.

I guess this never generated enough heat because there is a tendency in the .NET world to use Custom Controls instead of subclassing, which is something very VFP-like. Beside the historical root (C++ and VB) for this, thes is a practical reason: while in VFP you tend to package lots of stuff in an EXE, this is usually done in separate assemblies in .NET, where Custom Controls are somewhat handier.

>I know this works with a lot of PEMs, I'm just curious about Fonts as an example, since they seem to be a stumbling block for the person who started this whole thread. And if it doesn't happen with Fonts, is there a list of "non-inheriting" PEMs somewheres within easy reach?

Well, what the designer overrides is seen in the code it generates, which is right there, so it is easy to find out.

My general approach to avoid problems with the designer is to avoid the designer. 8-) I usually cook UI stuff either on code or dinamically, if I need to do it at all. I'm more of a back-end guy...

Regards,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform