So I'm working on a basic subclass of Label that supports editing. The editing part works fine--I insert a text box with no background color or border on click, commit changes on enter or loss of focus.
The little thing that's giving me trouble is related to some basic font styling. The label is to underline with the MouseHover event (like a hyperlink) and then lose the underline afterwards. Most of the time, it works, but occasionally, the MouseHover will cause the font to revert to the Winforms default--8pt sans-serif--instead of performing the operation.
Here's the event handler:
void BWEditableLabel_MouseHover(object sender, EventArgs e)
{
_fontBeforeHover = Font;
Font hoverFont = new Font(
_fontBeforeHover.FontFamily.Name,
_fontBeforeHover.Size,
_fontBeforeHover.Style | FontStyle.Underline
);
Font = hoverFont;
}
Some of you may observe that the last line doesn't simply say:
Font = new Font(Font, Font.Style | FontStyle.Underline)
I tried that, and the problem came about. The current version before you was an attempt that I made to resolve the issue.