I have a custom HyperLinkEdit inherited from HyperLinkEdit. I know DE controls dont inherit font from parent. But here I do need to. How do I say this control always have to inherit font from parent with minimal code?
I tried
C#protected override void OnParentFontChanged(EventArgs e)
{
base.OnParentFontChanged(e);
Font = new Font(Parent.Font.FontFamily, Parent.Font.Size, Parent.Font.Style | FontStyle.Underline);
}
The problem here is this is hit only if Parent's font is explicitly set. It doesnt get called when Parent has a default font.
I also tried
C#protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Font = new Font(Parent.Font.FontFamily, Parent.Font.Size, Parent.Font.Style | FontStyle.Underline);
base.OnPaint(e);
}
But this causes a freeze effect and things are painted correctly only if I drag and move the form. Screenshot: https://pasteboard.co/H2rTRvL.png
Now my custom control could be in inside a user control which could be inside form etc. I just want my control to have font from its immediate parent. Parent can have default font or custom font set programmatically or in designer. What would be the correct event or override?
I prefer not to make use of style controller because that means I got to add style controller in every control my HyperLinkEdit is going to be used. I prefer a solution where I only have to make change in my own control class.