此示例显示数值范围内的 Unicode 字符。输入要显示的最小值和最大值以及字体大小。然后单击列表以显示范围内的字符。将鼠标移到字符上时,左下角的文本框会显示字符的代码。其右侧的标签显示字符的示例。
示例字符很有用,因为TextBox并不总是能够很好地知道鼠标下方的字符。例如,如果您仔细查看图片,您会发现鼠标位于实际选定字符的左下方。您可以使用示例来验证您是否选择了所需的字符。
请注意,有些字符会使TextBox产生混淆。例如,如果您尝试列出字符 0 到 100,您将看不到任何内容。如果您尝试列出字符 1 到 100,您将得到许多有趣的结果。
本示例使用以下代码来显示字符。
// Display the desired Unicode characters
private void btnList_Click(object sender, EventArgs e)
{
txtChars.Clear();
txtCharCode.Clear();
Cursor = Cursors.WaitCursor;
Refresh();
// Set the font size.
float font_size = float.Parse(txtFontSize.Text);
txtChars.Font = new Font("Times New Roman", font_size);
// Display the characters.
int min = int.Parse(txtMin.Text);
int max = int.Parse(txtMax.Text);
StringBuilder sb = new StringBuilder();
for (int i = min; i <= max; i++)
sb.Appen