Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C#.Net Newbie Question - Subclassing A Button
Message
From
03/10/2005 16:38:22
 
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01017131
Message ID:
01055634
Views:
23
Sorry, just mistakenly addressed this to myself.

Hey Kevin,

It seems that I was too quick in my response to your message. Your modified code essentually provides default functionality for both Get and Set accessors, so overriding the property does nothing. Form designer adds Control.Font = new Font(...) line to form's code. The line is executed after the control is instantiated and this breaks inheritance. I am usinv VB. Perhaps, it works differently in C#. It seems the only way for me to enforce inheritance for fonts is to use your original approach. Of course, it will not allow to make changes to font settings via property sheet. An aternative would be to manually remove the line generated by the designer. However, it does not seem to be a practical solution.

Thanks,

Yuriy



>Hey, Yuriy,
>
>Just as a follow-up, I learned one additional thing after making that post. So here is the code I'm using now:
>
>
>public class MyTextBox : System.Windows.Forms.TextBox
>{
>     public override Font Font
>      {
>        get { return base.Font; }
>	set {base.Font = value; }      // new line
>	}
>
>	public MyTextBox()
>	{
>	base.Font = new  Font("Tahoma",8);
>        }
>}
>
>
>The code I previously posted would handle the inheriting the way you'd expect....but didn't allow you to change the font in the property sheet. You were totally restricted to the font defined in the base class. The small change above allows you to do so.
>
>
>
>Kevin
Yuri Rudenko
MCSD, MCP
Previous
Reply
Map
View

Click here to load this message in the networking platform