Windows Forms HelpProvider – Add Unicode Support

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
var helpProvider = new HelpProvider();
helpProvider.SetHelpString(button, "متن آزمایشی");
helpProvider.SetShowHelp(button, true);

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:

  1. The default font which is used by underlying API of the HelpProvider doesn’t support unicode characters
  2. 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

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!

You May Also Like

About the Author: Reza Aghaei

I’ve been a .NET developer since 2004. During these years, as a developer, technical lead and architect, I’ve helped organizations and development teams in design and development of different kind of applications including LOB applications, Web and Windows application frameworks and RAD tools. As a teacher and mentor, I’ve trained tens of developers in C#, ASP.NET MVC and Windows Forms. As an interviewer I’ve helped organizations to assess and hire tens of qualified developers. I really enjoy learning new things, problem solving, knowledge sharing and helping other developers. I'm usually active in .NET related tags in stackoverflow to answer community questions. I also share technical blog posts in my blog as well as sharing sample codes in GitHub.

Leave a Reply

Your email address will not be published. Required fields are marked *