Recently, when I was working on a project, I encountered the need to perform the upper and lower mark processing in the text box. The simple text control textbox cannot meet this function and must be implemented using the Rich Text control RichTextBox. The specific effect is as follows:
Before setting the upper font size: After setting the upper font size
SpecificCodeAs follows:
This. richtextbox1.selectedtext = "mm ";
This. richtextbox1.selectionfont = new font ("", 8, fontstyle. Regular );
This. richtextbox1.selectioncharoffset = 3; // The pixel of the displacement. The positive value is the move up, and the negative value is the move down.
This. richtextbox1.selectedtext = "2 ";
The code is very simple, but there is a note: This. richtextbox1.selectionfont = new font ("", 8, fontstyle. regular); the location of this line of code is critical. If it is displayed on the last line or the first line, the font size of the entire richtextbox1 is 8, and the entire display is small. If it is not set, the default font is font 10. The 2 above is displayed, as shown in figure.