在涉及到单位时,我们经常需要使用到上标和下标,在网上搜了一下,RICHTEXTBOX还是挺好用的,用法如下:
private void form_Load(object sender, EventArgs e)
{
Font richFont = new Font("宋体", 10);
richTextBox1.Font=richFont; //在c#中需要定义一FONT变量,在VB中可以不定义,直接设置FONT属性
richTextBox1.Text = "H2SO4";
OffsetRichText(richTextBox1,1,1,2);
OffsetRichText(richTextBox1, 4, 1, -2);
}
private void form_Load(object sender, EventArgs e)
{
Font richFont = new Font("宋体", 10);
richTextBox1.Font=richFont; //在c#中需要定义一FONT变量,在VB中可以不定义,直接设置FONT属性
richTextBox1.Text = "H2SO4";
OffsetRichText(richTextBox1,1,1,2);
OffsetRichText(richTextBox1, 4, 1, -2);
}
private void OffsetRichText(RichTextBox box, int iStart, int iLength, int iOffset)
{
box.SelectionStart = iStart;
box.SelectionLength = iLength;
Font richFont1 = new Font("宋体", box.Font.Size - System.Math.Abs(iOffset));
box.SelectionFont = richFont1;
box.SelectionCharOffset =iOffset;
box.SelectionStart = 0;
box.SelectionLength = 0;
}