如何根据Alt代码获取对应字符?代码实现方案咨询
Get Alt+1 Character in C#
Hey there! Let's get that Alt+1 character (the one that shows up as 鈽�) into your string and display it in the RichTextBox like you want. Here's a straightforward implementation for the AltCodes helper class you're looking for:
Implementation Code
public static class AltCodes { // Retrieves the character corresponding to the given Alt code number public static char GetAltCodeCharacter(int altCode) { // Alt codes 0-255 map directly to ASCII values // Alt+1 corresponds to the ASCII control character SOH (Start of Header) return (char)altCode; } } // Usage in your form code private void LoadSmileyCharacter() { string smiley = AltCodes.GetAltCodeCharacter(1).ToString(); // This will display the placeholder character (鈽�) since SOH is a non-printable control character richTextBoxHappy.Text = smiley; }
A Quick Note
That 鈽� placeholder appears because the character you're fetching (ASCII value 1, SOH) is a non-printable control character—most system fonts don't have a visible glyph for it. But this code correctly retrieves the exact character generated by pressing Alt+1, which is why you see that placeholder in your RichTextBox.
内容的提问来源于stack exchange,提问作者Shiasu-sama
相关产品推荐
相关产品推荐

