dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.36k stars 968 forks source link

TreeView and ComboBox do not correctly display #7282

Open phillipstoll opened 2 years ago

phillipstoll commented 2 years ago

.NET version

Version: 6.0.300

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Windows Forms TreeView and ComboBox controls, when used with Verdana Font, do not correctly display certain Latin-8 (ISO-8859-14: Celtic) characters. Certain characters are displayed as squares. E.g., Ḃḃ£ĊċḊ§Ẁ©ẂḋỲ®Ÿ appears as □□£Ċċ□§Ẁ©Ẃ□Ỳ®Ÿ . For the ComboBox the squares appear only in the drop-down. It works correctly with some fonts (Arial) but not with others (Arial Black). It doesn't occur on other common controls such as TextBox, Button, Label, CheckBox, RadioButton, CheckedListBox. Note: fixing it in .NET 5 won't help me because our software is at .NET 4.8

Issue description

TreeViewComboBox

Steps to reproduce

Add a Windows Forms App Add a TreeView controls to the form Change the TreeView's FontFamily to Verdana Edit the TreeView's Nodes collection, and add a node with the text Ḃḃ£ĊċḊ§Ẁ©ẂḋỲ®Ÿ

Cassie-Li01 commented 2 years ago

This issue can repro on .NET Core and .NET framework

Steps to reproduce

  1. Create a WinForms .NET Core/.NET framework app
  2. Add a TreeView controls to the form
  3. Change the TreeView's Font to Verdana in properties window
  4. Click smart tag, click edit nodes, add a node and change the text to "Ḃḃ£ĊċḊ§Ẁ©ẂḋỲ®Ÿ" or open attached project, open form WinFormsApp13.zip repro image
merriemcgaw commented 2 years ago

Thank you for reporting this issue as it shows up in both Core and Framework. In .NET Core we can look at this in the future and we will take a look when we have the chance. It is unlikely that we will be able to fix this in .NET Framework however because the servicing bar is extremely high at this point. We'll be happy to increase the priority of the issue in .NET if we find that there are other customers reporting this problem.

JeremyKuhne commented 2 years ago

This is most likely a limitation of the underlying Windows common controls. The first character in question does not actually exist in Verdana or Arial Bold. The Unicode character here is 1E02. You can see that it doesn't match by running the Character Map tool and enabling the advanced view. Some controls are obviously grabbing from another font (likely Arial) to fill in glyph gaps.

image

image

You can see this more clearly by using a more stylistic font such as "Bauhaus 93".

image

JeremyKuhne commented 2 years ago

Here is a possible workaround for this limitation in TreeView. Setting the DrawMode to TreeViewDrawMode.OwnerDrawText, adding an event handler to DrawNode and:

private void TreeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
    e.DrawDefault = true;
}

image

It isn't clear as to why the Windows tree view isn't rendering the missing glyphs. Thought it might have something to do with theming, but I can't reproduce the behavior when calling the theming APIs directly (which WinForms exposes in VisualStyleRenderer).

JeremyKuhne commented 2 years ago

With ComboBox you can do something similar, but you actually have to do the drawing of the text in the DrawItem event handler.