I made a custom control that is basically a multiline TextBox that allows input, and some other controls on the side that report some information. Now, I wanted to allow the user of my control to change the font in the TextBox, and thought something along the lines of: “Well, the user shouldn’t be able to change the font of other controls, so I’ll link it through the Font property on the control”, and hence ended up with the following code:
public override Font Font {
get { return txtEntry.Font; }
set { txtEntry.Font = value; }
}
(Yes, hungarian notation on my controls… Old VB habits die hard…)
Now, this would appear fine, except that when I built my project and went back to my form to see the effect, Visual Studio crashed. And crashed reliably when starting the project back up again… I opened the class in Notepad and changed it to a different name, deleted the output folders and opened Visual Studio, rebuilt, and it’s all working fine now.
My question is this: is there some inherant design flaw in my idea, or is this purely a VS bug?
Font is an ambient property. This means that, if it is not set, the control looks at the parent’s property to get its value. So, you have a recursive function because the parent’s Font property looks at the child’s, and around we go.
BTW, don’t feel bad; I asked the exact same question once 🙂