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
>Thank you, Kevin! That's it! Now I see where my problem was. Font is an ambient property, which, if not set, gets its value from container object. Forms designer just tries to preserver the value I set at the subclass level. It does it in a weird way, I should say. Your approach solves the problem, at least for me and for now.
>
>Thanks again,
>
>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