我在使用vb.net在Richtextbox中添加Superscript和Subscript时出现问题,有人可以帮忙吗?
答案 0 :(得分:1)
在这里,直接来自MSDN网站:
Private Sub WriteOffsetTextToRichTextBox()
' Clear all text from the RichTextBox.
RichTextBox1.Clear()
' Set the font for the text.
RichTextBox1.SelectionFont = New Font("Lucinda Console", 12)
' Set the foreground color of the text.
RichTextBox1.SelectionColor = Color.Purple
' Set the baseline text.
RichTextBox1.SelectedText = "10"
' Set the CharOffset to display superscript text.
RichTextBox1.SelectionCharOffset = 10
' Set the superscripted text.
RichTextBox1.SelectedText = "2"
' Reset the CharOffset to display text at the baseline.
RichTextBox1.SelectionCharOffset = 0
RichTextBox1.SelectedText = ControlChars.CrLf + ControlChars.CrLf
' Change the forecolor of the next text selection.
RichTextBox1.SelectionColor = Color.Blue
' Set the baseline text.
RichTextBox1.SelectedText = "777"
' Set the CharOffset to display subscript text.
RichTextBox1.SelectionCharOffset = -10
' Set the subscripted text.
RichTextBox1.SelectedText = "3"
' Reset the CharOffset to display text at the baseline.
RichTextBox1.SelectionCharOffset = 0
End Sub
答案 1 :(得分:0)
上标
Private Sub SuperScriptMenuItem_Click(sender As Object, e As EventArgs) Handles SuperScriptMenuItem.Click
Try
If RichTextBox1.SelectedText = "" Then
MsgBox(" Please select the text first", MsgBoxStyle.Information, "Select")
Else
RichTextBox1.SelectionCharOffset = 10
RichTextBox1.SelectedText = RichTextBox1.SelectedText
RichTextBox1.SelectionCharOffset = 0
End If
Catch ex As Exception
MsgBox(" This formatting can't possible", MsgBoxStyle.Information, "Superscript")
End Try
End Sub
对于下标
Private Sub SubScriptMenuItem_Click(sender As Object, e As EventArgs) Handles SubScriptMenuItem.Click
Try
If RichTextBox1.SelectedText = "" Then
MsgBox(" Please select the text first", MsgBoxStyle.Information, "Select")
Else
RichTextBox1.SelectionCharOffset = -10
RichTextBox1.SelectedText = RichTextBox1.SelectedText
RichTextBox1.SelectionCharOffset = 0
End If
Catch ex As Exception
MsgBox(" This formatting can't possible", MsgBoxStyle.Information, "Subscript")
End Try
End Sub