There is a great article about unicode manuplation in csharp.
http://csharphelper.com/blog/2014/09/explore-unicode-characters-c/[
^]
Also the above link provides binary executable which you can print available unicode characters in the font "Times New Roman".
However, when I try to draw this unicode characters using DrawString method, many of the unicode characters displayed in the text box are just drawn as hallow sqare (i.e. unsupported character) whereas the same characters are shown correct form in the text box.
I have used the same font "Times New Roman" with DrawString method.
I am just curious why there is some discrepancy between textbox and DrawString method even if I am using the same font.
Ocassioanlly, I can draw some characters using Draw String method but many of them are drawn as blank square.
There seems no consistency between these two methods even using the same font.
There shoud not be any discrepancy because I supply "Times New Roman" font in the DrawString method, isn't it?
Is there any clean solution or work around on this problem ? I really want to see both text box and DrawString method give the same results.
Here is the screenshot of it if you need more information about this problem.
https://www.photobox.co.uk/my/photo/full?photo_id=502475949276[
^]
What I have tried:
Here is my code of attempting to draw unicode characters using DrawString Method.
int unicodeIndex = 10728;
this._provider = new CultureInfo("en-us");
string unicodeString = ((char)unicodeIndex).ToString(_provider);
this.Font = new Font("Times New Roman", arrowSize);
int x = 200;
int y = 200;
SizeF sizef = g.MeasureString(unicodeString+"W", this.Font, new PointF(x, y), _sformat);
int w = Convert.ToInt32(sizef.Width) + 2;
int h = Convert.ToInt32(sizef.Height) + 2;
RectangleF rectf = new RectangleF(x, y-h/2, w, h);
g.DrawString(unicodeString, this.Font, myBrush, rectf, myFormat);
This is the original code displaying unicode in Text Box using Times New Roman font from the above link shared.
private void btnList_Click(object sender, EventArgs e)
{
txtChars.Clear();
txtCharCode.Clear();
lblSample.Text = "";
Cursor = Cursors.WaitCursor;
Refresh();
float font_size = float.Parse(txtFontSize.Text);
Font font = new Font("Times New Roman", font_size);
txtChars.Font = font;
lblSample.Font = font;
int min = int.Parse(txtMin.Text);
int max = int.Parse(txtMax.Text);
StringBuilder sb = new StringBuilder();
for (int i = min; i <= max; i++)
sb.Append(((char)i).ToString());
txtChars.Text = sb.ToString();
txtChars.Select(0, 0);
Cursor = Cursors.Default;
}