用 RichTextBox控件,(菜单 工程》部件》选 microsoft Rich Txtbox...) Private Sub Form_Load()
RichTextBox1.Font.Name = "Times New Roman"
RichTextBox1.Font.Size = 10
RichTextBox1.Text = "H2SO4"
'注释: Move the numbers down 2 points.
OffsetRichText RichTextBox1, 2, 1, 2 '
字串中第二个设为上标
OffsetRichText RichTextBox1, 5, 1, -2 ' 字串中第5个设为下标
End Sub'设置上下标
Private Sub OffsetRichText(box As RichTextBox, start As Integer, length As Integer, offset As Integer)
'注释:box指RichTextBox控件;start指作为上下标的
'注释:字符的起始位置;length指上下标字符的长度;
'注释:offset指上标还是下标,大于0上标;小于0下标。
box.SelStart = start - 1
box.SelLength = length
box.SelFontSize = box.Font.Size - Abs(offset)
box.SelCharOffset = ScaleY(offset, vbPoints, vbTwips)
box.SelStart = 0
box.SelLength = 0
End Sub