在RichTextBox 控件中实现上、下标形式 VB提供了一个优秀的控件RichTextBox,我们可以在其中实现文本的各种编辑方式。下面的程序是在RichTextBox 控件中实现上标和下标的形式,主要是使作为上、下标的字符的尺寸小一些,位置在基线上下浮动。程序利用属性SelCharOffset,由它确定RichTextBox 控件中的文本是出现在基线上(正常状态),当SelCharOffset >0 时,文本出现在基线之上,成为上标形式; 当SelCharOffset< 0 时,文本出现在基线之下,成为下标形式。 该属性在设计时无效。 在表单的Load事件中添加以下代码: 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, 1, 1, 2 OffsetRichText RichTextBox1, 4, 1, -2 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 box.SelLength = length box.SelFontSize = box.Font.Size -abs(offset) box.SelCharOffset = ScaleY(offset,vbPoints, vbTwips) box.SelStart = 0 box.SelLength = 0 End Sub 上述程序在WINDOWS98/ME中通

评论