The built-in HelpProvider component of windows forms is suffering from an old problem; it’s unable to show unicode characters (for example Persian language). Even if you try to show a help popup using Help.ShowPopup, when you a specify a help string containing special Unicode characters like Persian or Arabic characters, the popup doesn’t show those characters correctly.
Here is a minimal code to reproduce the problem:
var f = new Form();
f.HelpButton = true;
f.MinimizeBox = f.MaximizeBox = false;
var button = new Button()
{
Text = "Click on help button and then on me!",
AutoSize = true
};
f.Controls.Add(button);
var helpProvider = new HelpProvider();
helpProvider.SetHelpString(button, "متن آزمایشی");
helpProvider.SetShowHelp(button, true);
f.Show();
And this is the ugly result that you see:
It will be remaining as it is, even if set the language for non-Unicode programs to “Persian” language (in regional settings).
The behaviour is because of following problems:
- The default font which is used by underlying API of the HelpProvider doesn’t support unicode characters
- The underlying API of the HelpProvider doesn’t support Unicode.
The first problem is in Help
class(.NET 4.X, .NET 5, .NET 6) which has created the HH_POPUP
but hasn’t specified any font for it. As a result a default font which doesn’t support Unicode characters will be used.
- A possible fix is using a default font like
SystemFonts.CaptionFont
which supports Unicode characters.
For the second problem, you need to change a setting in Windows, to do so:
- Go to Control Panel → Region → Administratve tab, then in the section “Language for non-Unicode programs”, click on “Change system locale …” button and then in the next dialog, choose the language of your choice, for example Persian. Or to support other languages as well you can choose: “Beta: Use Unicode UTF-8 for worldwide language support” which is Beta.
Then it will work as expected:
I’ve created a HelpProvider2
component which supports Unicode characters. It also exposes Font
, ForeColor
and BackColor
properties:
The example also contains a HelpExtensions.ShowPopup2
which can be used instead of Help.ShowPopoup
:
HelpExtensions.ShowPopup2(button1, "متن آزمایشی", Control.MousePosition);
Download or clone
- Repository: r-aghaei/HelpProvider2Example.git
- Download master.zip
Note: I’ve reported it to the new windows forms repository and you can see the issue and the suggestions here: HelpProvider is unable to show Unicode characters #4422. It’s already up for the grab; so if you have time and you are passionate about it, then go ahead!