1
我想使用組合框在richtextbox中更改爲字體大小,如果我們在使用此代碼的選擇文本中有一種字體,則可以輕鬆更改字體大小。richtextbox中的setselction字體大小vb.net中的多種字體
RichTextBox1.SelectionFont = New Font(SelectionFont.FontFamily, CInt(ToolStripComboBox3.Text), RichTextBox1.SelectionFont.Style)
但是,如果我們在我們選擇多種字體也沒有作用。我有另一個代碼來解決這個問題。但是這個代碼的唯一問題是少於2000個字符,但是當選擇文本很大時,它是毫無價值的。代碼如下。任何幫助......
Public rtbTemp As New RichTextBox()
Public Sub ChangeFontSize(ByVal rtb As RichTextBox, ByVal fontSize As Single)
'This method should handle cases that occur when multiple fonts/styles are selected
' Parameters:-
' fontSize - the fontsize to be applied, eg 33.5
If fontSize <= 0.0 Then
Throw New System.InvalidProgramException("Invalid font size parameter to ChangeFontSize")
End If
Dim rtb1start As Integer = rtb.SelectionStart
Dim len As Integer = rtb.SelectionLength
Dim rtbTempStart As Integer = 0
' If len <= 1 and there is a selection font, amend and return
If len <= 1 AndAlso rtb.SelectionFont IsNot Nothing Then
rtb.SelectionFont = New Font(rtb.SelectionFont.FontFamily, fontSize, rtb.SelectionFont.Style)
Return
End If
' Step through the selected text one char at a time
rtbTemp.Rtf = rtb.SelectedRtf
For i As Integer = 0 To len - 1
rtbTemp.[Select](rtbTempStart + i, 1)
rtbTemp.SelectionFont = New Font(rtbTemp.SelectionFont.FontFamily, fontSize, rtbTemp.SelectionFont.Style)
Next
' Replace & reselect
rtbTemp.[Select](rtbTempStart, len)
rtb.SelectedRtf = rtbTemp.SelectedRtf
rtb.[Select](rtb1start, len)
Return
End Sub
錯誤:選擇不使用VB2008表達 – user934820
它的工作對我來說,我使用VS 2010 .NET4 – surpavan
然後,它需要框架3.5,IAM工作的框架2.0,希望System.Windows.Forms.RichTextBox IAM會員對於任何其他解決方案 – user934820