04-04-2019 04:40 PM - last edited on 04-04-2019 06:04 PM by Kristi_Martinez
Hello all,
I'm afraid the answer to this question is probably going to be "you just can't do that," but I'm posting just in case there is some genius out there that has an idea to make it work.
I want to draw text on a .NET picture box. I have the "UseUnicode=true" ini flag and I am able to type unicode into string controls and display it properly. However when I wire that string control into the "DrawString" .NET node, it treats it as though it was a regular ascii string that's twice as long (I guess) and doesn't draw it properly.
Does anyone know a way to draw unicode text into a .NET picture box?
(attached is a VI with my attempt)
Solved! Go to Solution.
04-04-2019 05:12 PM
Oops sorry, realized I had a missing VI. See attached VI instead.
04-05-2019 09:24 AM
Try changing the font family to Symbol. This doesn't have all Greek letters but it has a lot of them, especially ones associated with math. You can find a character map online to know what HEX values to use. Change the text box to display HEX values and type in the values you need. I understand that Arial Unicode MS font supports all of the Greek characters but I do not see it as an option on computers without Office installed. Ideally, you find a font that is installed by default with Windows, otherwise you would need to buy a font or locate a free one online. Lucida Sans Unicode may work for you.
There is a VI called "Color to RGB". It will convert LabVIEW color to RGB values (minus the Alpha channel). Press Control+Spacebar and search for RGB.
I wouldn't put this code in the Timeout case. Create a value change event for the string control, change the string control to "Update Value While Typing" and put the drawing code there. That way, the code isn't making unnecessary .NET calls when the value hasn't changed.
04-05-2019 11:54 AM
Thanks for your suggestion! I just tried it, but sadly it still isn't working for me. I have the Lucida Sans Unicode font installed, but when I put that in instead of Arial, I get the same result (except the nonsense characters that show up are styled slightly differently).
I think the problem is that the DrawString function is interpreting the string like strictly each character is 1 byte, that's why its displaying six characters when I only have 3, but I need it to interpret the string like it's UTF-8. I guess there's no way to do this? Or maybe there is some other .net function that does it?
04-05-2019 12:06 PM - edited 04-05-2019 12:11 PM
See attached. It works for me. Start typing in the text box and the picture will update.
Edit: Virus scan failed on the VI. Not sure why so i'm zipping it.
04-05-2019 12:42 PM
Oh, I see, you mean to not use unicode at all and just use a font that maps to greek symbols. Hmm, yes this might work, but I'm worried then we would need to find a special font for each language we support and work out the mapping for all the characters, and I'm afraid that could be brittle and not very scaleable.
Our goal is that once the program is built into an executable, it can support any new language just by being provided a new translation file, without re-building the executable.
04-05-2019 01:02 PM
Ok I think I've figured it out! You got me on the right track, realizing that using unicode just isn't going to work for this. But there is a way to make it work using the windows settings.
In case anyone else has this problem later, what I did was change the language for non-unicode programs:
Once you change this it will work to display text in that language without using unicode - I don't know how exactly it does work, but somehow it does (?). It's not as flexible as I would prefer, because you can only use one language at a time, but it does work and this way I don't have to play around with finding the mapping to a special font that may or may not contain all the characters for whatever language I'm using.